7

I played with Java 7 update 9 on mac a little bit and found an interesting thing.

I just ran a simple Java program with a JFrame, and attach to it with lldb. Then I checked libraries loaded by this Java program and I saw:

"/System/Library/Frameworks/JavaVM.framework/JavaVM" in it.

So i have 2 questions:

  1. what does this JavaVM do for Java 7? I thought Java 7 on mac is self-consistent like its corresponding versions on Windows and Linux. By using "nm", I can see this JavaVM defined many functions like JNI_CreateJavaVM, which is also defined in libjvm.dylib.

  2. what should I link to for JNI libraries with Java 7? still JavaVM.framework? Can I link to libraries located under

    /Library/Java/JavaVirualMachine/jdk.1.7.0 directly.

Any help will be much appreciated.

Jhanvi
  • 5,069
  • 8
  • 32
  • 41
bli0406
  • 91
  • 4
  • possible duplicate of [Need help understanding Oracle's Java on Mac](http://stackoverflow.com/questions/15120745/need-help-understanding-oracles-java-on-mac) – BryanH Oct 10 '13 at 01:14

2 Answers2

0

For the first part, that JavaVM points to the Mac JavaVM (1.6). Taking a closer look at the Info.plist files, it looks like the Mac Java supports JNI (amongst other things), while the Oracle Java supports only CommandLine. It does not look like you can link to 1.7 on Mac OS X. There's plenty of related questions, too.

To find your JVMs that support JNI, do this:

/usr/libexec/java_home -t JNI

This should probably return the 1.6.0 JDK. You can run it with the -V argument to get a full listing of what JVMs are available.

Matt
  • 637
  • 3
  • 10
  • We use JNI all the time with the Oracle 1.7. Do you mean only calling _into_ java, perhaps? – bmargulies Dec 15 '13 at 01:06
  • @bmargulies on Mac OS X? And it's not using 1.6? – Matt Dec 15 '13 at 01:31
  • Does java_home -t JNI give you 1.7? Or is that for calling into Java like you mentioned? – Matt Dec 15 '13 at 01:34
  • I see the same thing you do. However, /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre/lib/libjava.dylib exists and has the usual API, and the headers are all there. I think that java_home is confused. – bmargulies Dec 15 '13 at 02:25
0

The Oracle JDK on Mac is advertised to be just like the Oracle JDK everywhere else. It's got commands, headers, and libs. You should be able to use the contents of the JDK just you would elsewhere. We commonly create and use JNI libs that get loaded with LoadLibrary; I can't report personal experience with the invocation interface.

bmargulies
  • 97,814
  • 39
  • 186
  • 310