Reputation: 11
I have two OpenJDK versions installed on a machine (8 and 11). If one of the products uses OpenJDK 8 and another one uses OpenJDK 11, will they pick up the respective OpenJDK version or I need to explicitly make that version current with update-alternatives?
update-alternatives --config java
Upvotes: 1
Views: 65
Reputation: 625
I'm no expert, but I think the answer to your question depends on the circumstances - a yes or no wouldn't apply to every scenario out there.
What I see a lot of people do is make a .bash_profile function for easily changing their JAVA_HOME or other environmental variables with a simple one-word command in terminal.
I use Java8 95% of the time, so haven't done this myself. Development-wise, for the vast majority of dependency managers, build tools, IDE's, etc. there is some way to specify the Java version for a specific project, workspace, or context, depending on where you need it. If you use Maven, for example, simply add:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
to you POM.xml
The equivalent for Gradle would be:
apply plugin: 'java'
sourceCompatibility = 1.8
targetCompatibility = 1.8
credit: How do I tell Gradle to use specific JDK version?
I believe there is a way to specify the JDK in META-INF/manifest.mf as well.
Sorry if that didn't answer your question. I have only needed to specify a specific JDK version for a handful of cases, and settings properties like these is typically how I do it.
Upvotes: 0
Reputation: 472
You can do that. Usual practice is setting that environment variable with installed java location then use short hand. Like java abc.java & javac abc something like that.
But if you want to use some diffenrt versions for different project you can use by providing absolute path Eg: if you java bin locations are /abc/xyz/java/jdk8/bin & /abc/xyz/java/jdk11/bin then you can use like /abc/xyz/java/jdk8/bin/java abc.java for java 8 compilation or like /abc/xyz/java/jdk11/bin/java abc.java for java11 compilation.
Also, Java support backward compatibility, means If the code is complied in java 8 can run in java11 run-time environment but Reverse is not true.
Upvotes: 1