Both java 8 and java 11 are installed on a server, default settings (JAVA_HOME) show java 11. Is it possible to run the code with java 8 without creating the jar file or by selecting java 8 while running the jar file?
Asked
Active
Viewed 250 times
-2
-
Can you give more context? You could just use an absolute path to your Java8 installation (`/use/lib/java-11/bin/java` for instance) rather than using just `java` to run it. – Gaël J Jun 06 '21 at 17:23
-
See this answer: [Running Java Programs in Windows 10 Command Prompt](https://stackoverflow.com/a/32365879/5221149) – Andreas Jun 06 '21 at 17:27
-
1'creating the jar file' is irrelevant; you can run a jar in any version of Java, and you can run non-jar 'exploded' class files in any version of Java – dave_thompson_085 Jun 06 '21 at 19:41
1 Answers
3
I'm not sure what your use case is; why you think you need to specify a version. However:
Your choice of "java version" is usually determined by which "java" you choose to run.
If you're using an IDE, you can select one or the other JVM.
If you're running from a shell script or a .bat file, you can specify a different path, e.g.
C:\Program Files\java\jdk-11.0.1\bin
orC:\Program Files\java\jre1.8.0_121\bin
.
If you're on Linux, you can use update-alternatives to specify a different "default" Java version.
You can also specify -version:release on your Java command line.
Q: Does that answer your question?

paulsm4
- 114,292
- 17
- 138
- 190
-
Your #3 `-version:release` no longer exists above 8, and in particular not in 11 – dave_thompson_085 Jun 06 '21 at 19:41
-
@dave_thompson_085: I'm not sure why the OP is asking about "selecting Java version" in the first place: it strikes me as a bit of a "non-problem" ;) ANYWAY - I just wanted to give as many options as I could think of. Thank you for pointing out that "-version:release" is now deprecated: I wasn't aware of that. Partially because I never use it/never needed to use it ;) – paulsm4 Jun 06 '21 at 20:40