Opened 5 years ago

Last modified 22 months ago

#58098 new enhancement

Install openjdk8 as default JVM

Reported by: giansalvo (gians) Owned by:
Priority: Normal Milestone:
Component: ports Version: 2.5.4
Keywords: Cc: breun (Nils Breunese), cooljeanius (Eric Gallager)
Port: openjdk8

Description

I'm trying to port a java based application (Arduino IDE) to MacPorts. The Arduino application is built correctly and Arduino.app get installed to /Applications/MacPorts folder.
However when I launch Arduino.app I get "Unable to load Java Runtime Environment".

I installed openjdk8 with sudo 'port install openjdk8'.
I have another JVM installed that looks like the default JVM (see attached files):

$ls  /Library/Java/JavaVirtualMachines/
jdk1.8.0_131.jdk	openjdk8

What is (if it's possible) the clean way to install openjdk8 as the default JVM?

Attachments (4)

Schermata 2019-02-18 alle 21.35.56.png (56.0 KB) - added by giansalvo (gians) 5 years ago.
Schermata 2019-02-18 alle 21.40.33.png (254.7 KB) - added by giansalvo (gians) 5 years ago.
Schermata 2019-02-19 alle 18.01.56.png (398.7 KB) - added by giansalvo (gians) 5 years ago.
Info-openjdk.plist (2.5 KB) - added by giansalvo (gians) 5 years ago.
this is Info.plist file found inside the macOS app bundle

Download all attachments as: .zip

Change History (20)

Changed 5 years ago by giansalvo (gians)

Changed 5 years ago by giansalvo (gians)

comment:1 Changed 5 years ago by ryandesign (Ryan Carsten Schmidt)

I don't know.

My understanding is ports should use the java 1.0 portgroup to indicate what JDK they want.

comment:2 Changed 5 years ago by jmroot (Joshua Root)

Cc: breun added

Are you just wanting to get this one port to use a specified JRE? That's different to setting it as the default.

comment:3 Changed 5 years ago by breun (Nils Breunese)

The standard way of setting your default JVM is by setting the JAVA_HOME environment variable.

When you install the openjdk8 port this message is displayed explaining this:

If you have more than one JDK installed you can make JDK 8 the default
by adding the following line to your Bash shell profile (~/.bash_profile):
    export JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk8/Contents/Home

You can check the value of JAVA_HOME by running echo $JAVA_HOME. On my machine I get this:

$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/openjdk8/Contents/Home

What do you get on your machine?

You can run /usr/libexec/java_home -V to get a list of all JVM's on your machine (as long as they're installed under /Library/Java/JavaVirtualMachines).

Another method is using /usr/libexec/java_home to find a JVM matching the desired Java major version like this:

$ /usr/libexec/java_home -v 1.8
/Library/Java/JavaVirtualMachines/openjdk8/Contents/Home

You could use that command in your Bash profile like this:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`

Although I prefer to set JAVA_HOME to an explicit location myself.

Changed 5 years ago by giansalvo (gians)

comment:4 in reply to:  3 Changed 5 years ago by giansalvo (gians)

Replying to breun:

The standard way of setting your default JVM is by setting the JAVA_HOME environment variable.

When you install the openjdk8 port this message is displayed explaining this:

If you have more than one JDK installed you can make JDK 8 the default
by adding the following line to your Bash shell profile (~/.bash_profile):
    export JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk8/Contents/Home

Yes I know. This is true for java applications that you launch from the terminal/shell. But I need to "link" the JVM with a macOS bundled java application (Arduino.app in the /Applications folder). As far as I could see the JAVA_HOME shell variable set in the Bash profile configuration file doesn't affect the .app application.

Furthermore as you can see from the third attached image, the .app file contains already the entire openjdk8 JRE.

comment:5 in reply to:  2 Changed 5 years ago by giansalvo (gians)

Replying to jmroot:

Are you just wanting to get this one port to use a specified JRE? That's different to setting it as the default.

I actually would like to link this specific port to openjdk8 JRE (which is already contained in the .app file). At worst I'd like to try setting it for the all system.

comment:6 Changed 5 years ago by breun (Nils Breunese)

If the app already contains an entire JRE, then I think it won't be necessary to have the openjdk8 port installed. I'm not very familiar with macOS GUI apps that use Java, but I guess the .app must contain some kind of start script that starts the java process with the correct arguments (using the java binary from the included JRE). Maybe you can take a look at the package contents of another macOS GUI app on how to do this. Dealing with the JAVA_HOME environment variable indeed shouldn't be necessary in this case.

Last edited 5 years ago by breun (Nils Breunese) (previous) (diff)

comment:7 Changed 5 years ago by kencu (Ken)

Alternatively there is a way to set environment variables using the plist file in the bundle that might be of use for this. You could set it to a specific JAVA_HOME perhaps.

<https://superuser.com/questions/476752/setting-environment-variables-in-os-x-for-gui-applications>

comment:8 in reply to:  6 Changed 5 years ago by giansalvo (gians)

Replying to breun:

If the app already contains an entire JRE, then I think it won't be necessary to have the openjdk8 port installed.

The app was built WITH openjdk8 and should contain it but somehow it isn't recognized or something like that.

Replying to breun:

I'm not very familiar with macOS GUI apps that use Java, but I guess the .app must contain some kind of start script that starts the java process with the correct arguments (using the java binary from the included JRE). Maybe you can take a look at the package contents of another macOS GUI app on how to do this.

It's exactly what I thought but I couldn't find any macOS GUI Java app already ported in MacPorts. Do you know any?

Changed 5 years ago by giansalvo (gians)

Attachment: Info-openjdk.plist added

this is Info.plist file found inside the macOS app bundle

comment:9 Changed 5 years ago by breun (Nils Breunese)

I'm not familiar with macOS GUI Java apps, but that Info.plist contains references to $JVM_RUNTIME. I don't know if that has a value and if so, where it would come from. The screen shot you attached also shows the openjdk8 dir to be in Contents/PlugIns/openjdk8, while the plist references $JVM_RUNTIME/Contents/Java (I don't know what's in there). If the JRE really is contained in the .app, then I don't think you'd need an environment variable like $JVM_RUNTIME, but should just be able to point to the Java directory inside the .app directly. I don't really think this is really a MacPorts question actually, maybe a place with people who know how to create a macOS .app with a JRE inside will be able to help you better.

comment:10 Changed 5 years ago by giansalvo (gians)

I was able to fix the problem using /usr/libexec/java_home to set JAVA_HOME environment variable.

comment:11 Changed 5 years ago by breun (Nils Breunese)

That method will not use the included JRE though, because /usr/libexec/java_home won't find that, so then users will need to have a separate Java installation.I guess it should be possible to point JAVA_HOME to the included JRE instead.

comment:12 Changed 3 years ago by zeddit (Dai Zhang)

I had the same issue.

I installed the openjdk8 from macports, and set the $JAVA_HOME following the notes. After that, I have checked that java can run in the terminal.

However, macOS application cannot load java runtime environment thus fail to run.

I uninstalled the openjdk8, and reinstall jdk from the java homepage's jdk8.dmg. This time, macOS application can run properly.

I checked the position where jdk8.dmg installs binaries, which is /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home, that is different from one macports installs.

I wonder if the mismatch of binary paths causes the macOS application cannot find JRE, and is there any method to fix this issue.

P.S. the macOS application I tested is VOSviewer.

Last edited 3 years ago by zeddit (Dai Zhang) (previous) (diff)

comment:13 Changed 3 years ago by breun (Nils Breunese)

/Library/Internet Plug-Ins is for browser plugins and the Java plugin for browsers has been discontinued a long time ago as far as I know. Are you trying to load a Java applet in your browser?

The openjdk8 also has a couple of variants that enable extra capabilities (see port variants openjdk8). Maybe the app you are trying to run needs one or more of those. The error messages so far don’t give me enough information to know what could be wrong. Is the java binary from the MacPorts port actually called, or maybe not even found by the app?

comment:14 in reply to:  13 Changed 3 years ago by zeddit (Dai Zhang)

Replying to breun:

/Library/Internet Plug-Ins is for browser plugins and the Java plugin for browsers has been discontinued a long time ago as far as I know. Are you trying to load a Java applet in your browser?

/usr/libexec/java_home return /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home. So I thought the jdk8.dmg installs binaries into this folder, and I have checked that the executable files under this folder are actually executable binaries instead of link files.

I am trying to start a macOS application, not a applet in browser. But I'm not sure if the application is implemented with inside browser and applet.

The application I tested is [VOSviewer](https://www.vosviewer.com/download) .dmg for macOS system.

The openjdk8 also has a couple of variants that enable extra capabilities (see port variants openjdk8). Maybe the app you are trying to run needs one or more of those. The error messages so far don’t give me enough information to know what could be wrong. Is the java binary from the MacPorts port actually called, or maybe not even found by the app?

I have tried to install openjdk8 with all variants, i.e. port install openjdk8 +Applets +BundledApp +JNI +WebStart, but the application still reports 'cannot load java runtime environment'.

I am not familiar with Java, so I am not certain if the application finds the JRE or there are some other issues. However, when installed with jdk8.dmg, everything work fine, so I guess the app cannot find the java.

Maybe you could download the app and have a test. Thanks.

comment:15 Changed 3 years ago by breun (Nils Breunese)

I downloaded both the versions for Mac OS X and the one for 'other systems'.

Running VOSviewer.app indeed shows a dialog saying Unable to load Java Runtime Environment. and then quits.

The download for 'other systems' is just a JAR file and that one works fine (although it does log an error message about CoreSVG):

~ % echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/openjdk8/Contents/Home
~ % java -jar Downloads/VOSviewer_1.6.16_jar/VOSviewer.jar

So, I guess there might be a bug in the logic in VOSviewer.app that tries to locate the Java Runtime Environment. This might be something to report to the developer.

comment:16 Changed 22 months ago by cooljeanius (Eric Gallager)

Cc: cooljeanius added
Note: See TracTickets for help on using tickets.