Add support for JVM options with jpype
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')
It can be helpful for setting up proxies too.
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.
Is anyone working on this one?
If nobody is working on this one, I can take over and implement the changes @baztian suggested in the review?
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.