To switch JVM for each project

I want to switch between JDK and JVM at startup and compilation

When studying Java, there are times when you want to use a different version depending on the project. For example, I like the latest java10 and later var type inference, but I can only use java8 in my business. Depending on where you reside, java4 there were. There are times when you have to study in an old environment. Rather, as of 2020, java10 can hardly be used in business ... There is a screen to specify jvm in eclipse etc., but it is an experiment how to actually specify it on the command line.

Check which JVM is loaded with java -version

I have a Main class compiled with java12 It is assumed that the environment variable JAVAHOME is set to the path to the JVM of java12. In that state, place the JVM of the java8 JVM in any directory, and enter the directory containing the java command in it.

bash


java -version 

Hit the command. Then

java version "12.0.1" 2019-04-16

Was displayed. In other words, even in the current directory, the JVM that passes through the classpath of the environment setting JAVAHOME is running.

Therefore,

bash


./java -version 

I explicitly specified the java command in the current directory. Then

java version "1.8.0_144"

And the JVM of the current directory started. So if you make the java command a full path or a relative path, you can pass the path no matter where you place the JVM?

So, I tried typing the following command in the project root with the JVM placed directly under the project root

bash


./jdk1.8.0_144.jdk/Contents/Home/bin/java -cp ./bin Main

Then

Exception in thread "main" java.lang.UnsupportedClassVersionError: Main has been compiled by a more recent version of the Java Runtime

I got this error. It is said that this Main class cannot be run on java8 because it is built on java12. In other words, the switch is successful.

Recommended Posts

To switch JVM for each project
How to switch the display of the header menu for each transition page
Introduction to kotlin for iOS developers ②-Project creation
Swipe to switch screens
[Spring Boot] How to create a project (for beginners)
How to loop Java Map (for Each / extended for statement)
[Swift 5] Recognize ON/OFF of Switch in custom cell for each cell
How to install Web application for each language in Nginx
Deploy Vapor Project to Heroku
How to make a hinadan for a Spring Boot project using SPRING INITIALIZR
Must-see for beginners! How to manage your Xcode project on Github
[Rails] How to change the page title of the browser for each page