python-javabridge icon indicating copy to clipboard operation
python-javabridge copied to clipboard

OS X Java VM problems

Open mpapierski opened this issue 9 years ago • 3 comments

I am trying to call Java method from a compiled Java class using Python code. I dont want to run "java" executable just to run my code this I find this library really promising. Im no expert on Java but my OS X dev machine has troubles finding libjvm.dylib.

My $JAVA_HOME is:

export JAVA_HOME=$(/usr/libexec/java_home)

My libjvm.dylib is located under $JAVA_HOME/../Libraries/libjvm.dylib:

$ find $JAVA_HOME/.. -iname "libjvm.dylib" 
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/../Libraries/libjvm.dylib

My Java is the default one shipped with OS X 10.10:

$ java -version
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)

But javabridge library does some nasty things to find libjvm.dylib. See https://github.com/CellProfiler/python-javabridge/blob/master/javabridge/jutil.py#L98-L113. I think this piece of code is just wrong. My point is there could be a better way to deal with libjni.dylib location.

Since I am not expert on Java, and I have basically zero knowledge about coding Java and JNI and java libs I think better approach is to try some "known paths" for different Java vendors. AFAIK there is only Oracle Java available at this moment.

After reading Java docs and materials on the internet (and examining my own system) it looks like there are two possible places where libjvm.dylib could be located:

  1. $JAVA_HOME/../Libraries
  2. $JAVA_HOME/jre/lib

My installation has only (1) option valid, and the second path is non existing.

Right now I can suggest to use (2) by default (most of sources on the internet suggests this), and maybe check if your Java on your OS X does the same as (1).

Could you replicate this issue?

Thanks!

mpapierski avatar May 03 '15 17:05 mpapierski

I think Java has not been shipped with Mac OS X since Mac OS X 10.6. Further, Java version 7u25 and below have been disabled by Apple on OS X. [Source]

It looks like we already try to look in the two locations that you suggest (see locate.py).

ljosa avatar May 03 '15 19:05 ljosa

Is this issue still a problem for anyone?

If the suggested paths are already checked, I would recommend closing this issue.

jbcoe avatar Jun 24 '16 17:06 jbcoe

The user does have a point, even if it leads to an issue that I don't care to resolve in the near future. There's code in locate.py (https://github.com/LeeKamentsky/python-javabridge/blob/master/javabridge/locate.py#L42) that does a nice job using the java_home program to find the JRE and then it's done in a different way in jutil.py.

So it could be cleaner and that's an issue, but maybe there's no bug. I think I'll leave it for now.

LeeKamentsky avatar Jun 24 '16 17:06 LeeKamentsky