jaydebeapi icon indicating copy to clipboard operation
jaydebeapi copied to clipboard

Add support for JVM options with jpype

Open FeatCrush opened this issue 6 years ago • 5 comments

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')

FeatCrush avatar Aug 30 '19 15:08 FeatCrush

It can be helpful for setting up proxies too.

dclong avatar Aug 30 '19 17:08 dclong

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.

thealmightygrant avatar Sep 04 '19 17:09 thealmightygrant

Is anyone working on this one?

dschiavu avatar Mar 02 '22 18:03 dschiavu

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

dschiavu avatar Jul 18 '22 16:07 dschiavu

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.

adliechty avatar Oct 21 '22 16:10 adliechty