S
S
Scorpio2019-04-03 13:57:22
Java
Scorpio, 2019-04-03 13:57:22

How does the OS understand what version java is asking for?

I work in linux mint.
Created a program on javaFX + jdk8 , compiled it into a jar .
Installed on Linux 2 versions: JRE 8 and 11 .
sudo apt-get install oracle-java8-installer
sudo apt-get install oracle-java11-installer
And it turns out that if I set version 11 by default:
sudo apt-get install oracle-java11-set-default
Then the program crashes without even starting (apparently due to the fact that javaFX was cut out from there)
And if 8
sudo apt-get install oracle-java8-set-default
Then everything works fine. So, how do I get the system to understand so that it runs my program with jre8, even if the OS defaults to jre11 (but jre8 is also installed)?
How are things with this in Windows, if there is a bunch of java? Or does it not depend on the OS, and you need to register configs somewhere in the program itself?

Answer the question

In order to leave comments, you need to log in

6 answer(s)
M
Maxim Fedorov, 2019-04-03
@Maksclub

On Linux (also UNIX), $PATH is an environment variable used to tell the shell where to look for executable files. $PATH provides a lot of flexibility and security for Linux systems and it can certainly be said to be one of the most important environment variables.
Programs/scripts located in the $PATH directory can be executed directly in your shell without specifying the full path to them. In this article, you will learn how to set the $PATH variable globally and locally.

O
Orkhan, 2019-04-03
Hasanly @azerphoenix

Maybe not the best solution, but you can "embed" the jvm of the desired version in the application
https://eax.me/java-without-jvm/

F
Frozen Coder, 2019-04-03
@frozen_coder

I’ll add to the already answered that it’s easy, fast and easy to install and switch to different sdk and their versions using sdkman
https://sdkman.io/usage

M
Maxim Moseychuk, 2019-04-03
@fshp

There is no way to add this information to the jar.
Only if you add a loader that will look for the desired jvm version and create a new process.

#
#, 2019-04-03
@mindtester

along the way, except for setting the default runtime in the paths (in Linux, there may still be environment variables for Java, but I don’t know)
and if we are talking about an IDE like IntelliJ, the project clearly indicates which runtime should be used with it
if you need to operate ready-made applications tailored for different runtimes, you will have to get out - rather, launch scripts with redefinition of environment variables and / or specifying explicit runtime launch paths, in most cases, will be enough

S
sergey, 2019-04-03
kuzmin @sergueik

man alternatives
did you try to read it?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question