Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for JVM options with jpype #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

FeatCrush
Copy link

Add parameter 'java_opts' to the connect() function.
'java_opts' is a list of strings which are given to the JVM while starting.

Example for Kerberos authentication:

java_opts = ['-Djava.security.auth.login.config=%path_to_jaas%','-Djava.security.krb5.conf='%path_to_krb5.conf']
conn = jaydebeapi.connect(jclassname='driver_class',url='url',driver_args={'user':'your_user'},java_opts=java_opts,jars='driver_jar')

@dclong
Copy link

dclong commented Aug 30, 2019

It can be helpful for setting up proxies too.

@thealmightygrant
Copy link

thealmightygrant commented Sep 4, 2019

A workaround that should cover this for most people until this PR is merged is to do something similar to this:

if not jpype.isJVMStarted():
  #NOTE: after this PR is closed: https://github.com/baztian/jaydebeapi/pull/116
  #      we can upgrade JayDeBeApi and remove this code
  args = []
  class_path = ["/app/jars/somejar.jar"]
  class_path.extend(jaydebeapi._get_classpath())
  args.append('-Djava.class.path=%s' % os.path.pathsep.join(class_path))
  args.append('-Dlog4j.configuration=%s' % 'file:/app/log4j.properties')
  jvm_path = jpype.getDefaultJVMPath()
  jpype.startJVM(jvm_path, *args)
conn = jaydebeapi.connect(jclassname=self.config.get('driver_class_name'),
                          url=cxn_string,
                          driver_args=[],
                          jars=["/app/jars/somejar.jar"])

Most of this, is taken straight from: https://github.com/baztian/jaydebeapi/blob/master/jaydebeapi/__init__.py#L160. Note that old jpype differs slightly from the newest JPype.

BTW, this is a method to get log4j from spitting warnings at you if anyone else has had trouble with the log4j:WARN No appenders could be found for logger...log4j:WARN Please initialize the log4j system properly. error.

@@ -367,12 +370,14 @@ def TimestampFromTicks(ticks):
return apply(Timestamp, time.localtime(ticks)[:6])

# DB-API 2.0 Module Interface connect constructor
def connect(jclassname, url, driver_args=None, jars=None, libs=None):
def connect(jclassname, url, driver_args=None, java_opts=None, jars=None, libs=None):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add the java_opt at the end of the args. Otherwise this change will break backwards compatibility for code that doesn't use kwargs but relies on the order of the arguments.

@@ -398,7 +407,7 @@ def connect(jclassname, url, driver_args=None, jars=None, libs=None):
libs = [ libs ]
else:
libs = []
jconn = _jdbc_connect(jclassname, url, driver_args, jars, libs)
jconn = _jdbc_connect(jclassname, url, driver_args, java_opts, jars, libs)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail on Jython. Please provide at least the parameter to _jdbc_connect_jython

@dschiavu
Copy link

dschiavu commented Mar 2, 2022

Is anyone working on this one?

@dschiavu
Copy link

If nobody is working on this one, I can take over and implement the changes @baztian suggested in the review?

@adliechty
Copy link

For what it's worth, I'd love to see this in main as well.
I tried the above work around, but was not sure where to insert the code.
Is the workaround from @thealmightygrant indented to be put in jpype source somewhere?
I see "self.config.get('driver_class_name') reference "self" which if in top level app will fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants