Open Application with another java version?
I am trying to launch an application with another java version . I saw on the wiki that it can be done using a small bash script which I did :
#!/bin/sh
export PATH=/usr/lib/jvm/java-8-openjdk/jre/bin/:$PATH exec /path/to/application "$@"
I saved the script to /usr/local/bin but every time I run the application it is still running with the default java version. Is there anything that I am doing wrong ?
Edited 21 Sep 2019. We only hold this version.
About this post
- Posted
- Archived
- Edited
- Score
- 2 · 100% up
- Kind
- Text
- ID
- d73d47
20 comments
You may need to also export
JAVA_HOME,JDK_HOME, etc depending on the application and which environment variables it looks for.And just to clarify, you are launching the application with the script?
No I am launching the application with wofi ; does that change things ?
Changing it via the script only changes it within that current context, such as if you
export JAVA_HOME="PATH"into the terminal, and thenecho $JAVA_HOMEit will be correct, but if you close and open another terminal, it will have been reset.This is the desired behavior if you just want to change temporarily for a single application and not system-wide, otherwise add it to
.bashrcor.profiledepending on your setup to take effect for all new terminals.If you want to just launch once, open terminal, export new JAVA_HOME value, and launch program from that terminal.
Why aren't you calling the Java executable directly instead of setting the path?
It is because I just want to launch an application with a specific java version. I want to just click the desktop file and the application should know to run with this specific version ?
Yes, in your script use something like this
/path/to/java8/bin/java -jar application.jar "$@"
Or JAVA_HOME
You might find the command
archlinux-javauseful. However, it changes the java version globally.Another option is to use something like sdkman to temporarily switch versions. This will handle path changes and such for the current context.
The command would end up looking something like this
sdk use java 8.0.222.hs-adpt && java -jar application.jar "$@"