I have a open jdk installed on my centos 7. I would like maven to use java 1.8. I wouldn't want to break the machine's java. What would be the best way to achieve this?
Running: mvn -v
`Maven home: /usr/share/maven
Java version: 1.7.0_131, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.131-2.6.9.0.el7_3.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-514.10.2.el7.x86_64", arch:
"amd64", family: "unix"`
running: java -version
`openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)`
Here is my mvn config
running : cat /usr/bin/mvn
`#!/bin/sh
if [ -f /usr/share/java-utils/java-functions ] ; then
. /usr/share/java-utils/java-functions
set_jvm
set_javacmd
fi
export M2_HOME="${M2_HOME:-/usr/share/maven}"
export JAVA_HOME; $M2_HOME/bin/mvn "$#"`
Running $yum search java | grep openjdk
`java-1.6.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.6.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.6.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.6.0-openjdk-javadoc.x86_64 : OpenJDK API Documentation
java-1.6.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.7.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.7.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
java-1.7.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.7.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.7.0-openjdk-headless.x86_64 : The OpenJDK runtime environment without
java-1.7.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.7.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.8.0-openjdk.i686 : OpenJDK Runtime Environment
java-1.8.0-openjdk.x86_64 : OpenJDK Runtime Environment
java-1.8.0-openjdk-accessibility.x86_64 : OpenJDK accessibility connector
java-1.8.0-openjdk-accessibility-debug.x86_64 : OpenJDK accessibility connector
java-1.8.0-openjdk-debug.i686 : OpenJDK Runtime Environment with full debug on
java-1.8.0-openjdk-debug.x86_64 : OpenJDK Runtime Environment with full debug on
java-1.8.0-openjdk-demo.x86_64 : OpenJDK Demos
java-1.8.0-openjdk-demo-debug.x86_64 : OpenJDK Demos with full debug on
java-1.8.0-openjdk-devel.i686 : OpenJDK Development Environment
java-1.8.0-openjdk-devel.x86_64 : OpenJDK Development Environment
java-1.8.0-openjdk-devel-debug.i686 : OpenJDK Development Environment with full
java-1.8.0-openjdk-devel-debug.x86_64 : OpenJDK Development Environment with
java-1.8.0-openjdk-headless.i686 : OpenJDK Runtime Environment
java-1.8.0-openjdk-headless.x86_64 : OpenJDK Runtime Environment
java-1.8.0-openjdk-headless-debug.i686 : OpenJDK Runtime Environment with full
java-1.8.0-openjdk-headless-debug.x86_64 : OpenJDK Runtime Environment with full
java-1.8.0-openjdk-javadoc.noarch : OpenJDK API Documentation
java-1.8.0-openjdk-javadoc-debug.noarch : OpenJDK API Documentation for packages
java-1.8.0-openjdk-javadoc-zip.noarch : OpenJDK API Documentation compressed in
java-1.8.0-openjdk-javadoc-zip-debug.noarch : OpenJDK API Documentation
java-1.8.0-openjdk-src.x86_64 : OpenJDK Source Bundle
java-1.8.0-openjdk-src-debug.x86_64 : OpenJDK Source Bundle for packages with`
I doubt you'll "break anything" by changing Maven's JRE to Java 1.8.
Run alternatives --config java to see what JVMs are currently installed. Ideally, if you have both JRE7 and JRE8, you should see both listed.
Simply modify your /usr/bin/mvn to point to the desired path.
Run mvn -version again. You should see the updated configuration.
ran:
yum install java-1.8.0-openjdk-devel
then:
alternatives --config javac
Selected the version required for my project.
Thanks for all the replies!
Related
This is my output when I try running my Xcode KMM project
jenv global -> openjdk version "1.8.0_212"
java -version -> {
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_212-b03)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.212-b03, mixed mode)
oracle64-11.0.10
}
echo $JAVA_HOME -> ***Nothing comes here***
./gradlew :shared:packForXCode -PXCODE_CONFIGURATION=${CONFIGURATION}
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/ch/AndroidStudioProjects/Test4001/androidApp/build.gradle.kts' line: 1
* What went wrong:
An exception occurred applying plugin request [id: 'com.android.application']
> Failed to apply plugin 'com.android.internal.application'.
> Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing `org.gradle.java.home` in `gradle.properties`.
----<<<<>>>>-----
Anywhere in my Terminal:
java -version -> {
java version "11.0.10" 2021-01-19 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.10+8-LTS-162)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.10+8-LTS-162, mixed mode)
}
jenv global -> oracle64-11.0.10
echo $JAVA_HOME -> /Library/Java/JavaVirtualMachines/jdk-11.0.10.jdk/Contents/Home
I would like to understand how and why Xcode could be picking up the wrong version, obviously besides the fact that it can't find JAVA_HOME
It looks like this happens because xcode can't find the setup java version and gets some sort of default value.
If you would try to run your xcode project right now (I only reproduced this on BigSur) it will not work because the java version will show as outdated.
If you inspect with jenv or java you will find that your innner project folders and general version of java are setup correctly.
To fix this I just add an "export JAVA_HOME=$(/usr/libexec/java_home -v)" or "source ~/.zshrc" or "source ~/.bash_profile" before your run your scripts in Xcode
Of course the global version or your java_home must be in the correct java version you want to use
I tried this but got no result -
$ java -XX:+PrintFlagsFinal -version | grep UnlockExperimentalVMOptions
openjdk version "1.8.0_265"
OpenJDK Runtime Environment (build 1.8.0_265-8u265-b01-0ubuntu2~20.04-b01)
OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)
Is the flag UnlockExperimentalVMOptions removed or
Am I doing something wrong or what??
UnlockExperimentalVMOptions is itself an experimental VM option :)
To see it in the list of flags, use -XX:+UnlockExperimentalVMOptions
java -XX:+UnlockExperimentalVMOptions -XX:+PrintFlagsFinal -version | grep UnlockExperimentalVMOptions
bool UnlockExperimentalVMOptions := true {experimental}
openjdk version "1.8.0_265"
OpenJDK Runtime Environment (build 1.8.0_265-b01)
OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)
BTW, there is a great project by Chris Newland - VM Options Explorer
I am trying to run a simple spring boot project with java 11 but I can not add it as jre. I am getting following error while adding it as jre
I am using following java version on maco os 10.13.16
java version "11.0.2" 2019-01-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)
I tried to use the similar path( Contents/Home/lib) for jdk10 and it recognised as jre 10. I think that STS is not able to read jrt-fs.jar for java 11.
Can somebody pleas give some advice?
The JRE home for Java 11.0.2 on macOS is
/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home
(no 'lib' at the end)
I have
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
in my pom.xml.
If I run mvn clean install then I can't run the compiled classes with Java 1.8 (I get crashes with errors like java.lang.NoClassDefFoundError: Could not initialize class when I try to).
I am forced to run
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home mvn clean install
if I want it to be able to run the built jar with java 8 without crashes.
How can I make it actually use the correct JDK that I want?
Here is how my machine seems to be set up by default
$ mvn -version
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T19:41:47+01:00)
Maven home: /usr/local/Cellar/maven/3.6.0/libexec
Java version: 11.0.1, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/openjdk-11.0.1.jdk/Contents/Home
Default locale: en_GB, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.2", arch: "x86_64", family: "mac"
$ java -version
openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)
$ echo $JAVA_HOME
$
I'm being very confused by the following happening in my terminal:
my-computer:~$ which java
/usr/bin/java
my-computer:~$ java -version
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
my-computer:~$ sudo su
Password:
my-computer:/Users/paulhabfast$ which java
/usr/bin/java
my-computer:/Users/paulhabfast$ java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
Can anyone explain me what is going on?
The way I understand it so far is that when I switch from the current user to the root user, I'm being served a different executable?
I'm running Mac OSX 10.9, but I thought I had a pretty standard unix environment.
Is there any additional information I can give?
/usr/bin/java is a wrapper that looks at your environment variables, try env to see these variables, for example JAVA_HOME.