Skip to content

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.

2 points20 comments
Open on Reddit
About this post
Posted
Archived
Edited
Score
2 · 100% up
Kind
Text
ID
d73d47

Author

8
posts
76
comments
2
media
View profile

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?

2 points

No I am launching the application with wofi ; does that change things ?

1 points

Changing it via the script only changes it within that current context, such as if you export JAVA_HOME="PATH" into the terminal, and then echo $JAVA_HOME it 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 .bashrc or .profile depending 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.

1 points

Why aren't you calling the Java executable directly instead of setting the path?

2 points

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 ?

1 points

You might find the command archlinux-java useful. However, it changes the java version globally.

1 points

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 "$@"

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.