Java_home path cannot be set - maven

I am using linux subsystem with Debian 10. I installed Java 17 and set the Java homepath to jdk 17.
The JAVA_HOME Path ist still java-11, but this isnt even installed.
echo %JAVA_HOME% set set JAVA_HOME=/usr/lib/jvm/java-17-oracle echo %JAVA_HOME%
%JAVA_HOME% set set JAVA_HOME=/usr/lib/jvm/java-17-oracle echo %JAVA_HOME%
I tried to change the home variable permanently, but it does not work.
Well? Still exception
Downloaded java versions
installed java version
How can i change the Java_Home path permanently.
Thank you in advance

If you install JAVA through your distro's default package manager(for example I use Ubuntu so I install Java(the OpenJDK version of Java) through APT [so the command to install OpenJDK's Java17 for example is sudo apt install openjdk-17-jdk]). Regardless of the version you install via APT, Java will be installed in the /usr/lib/jvm/{java-version-distribution-architecture} path. So, the easiest way to set the JAVA_HOME variable is to edit your .bashrc file and add this inside it using your text editor:
JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64
export JAVA_HOME
PATH=$PATH:JAVA_HOME/bin
export PATH
Save and close the file after adding this information inside it. Then run the command source .bashrc(to stamp you changes) and the JAVA_HOME will be permanently set. Also note that the .bashrc file is located in the ~/.bashrc(your home). You can confirm the JAVA_HOME variable by using the command echo $JAVA_HOME on the terminal and it should show you the path you just set. I hope this helps

Related

Ubuntu maven The JAVA_HOME environment variable is not defined correctly

I installed maven in Ubuntu 22.04 and I am getting the next error when I try a mvn clean install command:
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE
My JAVA_HOME has the next value:
echo $JAVA_HOME
/usr/lib/jvm/java-11-openjdk-amd64/bin/
Am I missing something?
Thanks!
JAVA_HOME needs to be one level up - /usr/lib/jvm/java-11-openjdk-amd64

macbook 10.15.5 install maven failed: NB: JAVA_HOME should point to a JDK not a JRE

I know there are a lot of questions/answers about this question, but all were failed in my case.
I installed jdk 1.8 and then installed maven3.6.3, java runs well but mvn command didn't work, see my command output and env:
java -version
java version "1.8.0_251"
Java(TM) SE Runtime Environment (build 1.8.0_251-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)
mvn -v
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE
mac OS version: 10.15.5
echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home
echo $PATH
/usr/local/apache-maven-3.6.3/bin:/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:.
config in ~/.bash_profile
export M2_HOME=/usr/local/apache-maven-3.6.3
PATH=$M2_HOME/bin:$JAVA_HOME/bin:$PATH:.
#Mac OSX 10.15.5 or later version need this configure
export JAVA_HOME=$(/usr/libexec/java_home)
export CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.
export PATH
I also source ~./bash_profile to make configure effective.
I would suggest revert all the changes you have made in ~/.bash_profile. Checkout my way to make the maven work:
Download latest maven zip package apache-maven-<version>-bin.zip from Apache maven download page.
Unzip it to any place, e.g: ~/Develop/apache-maven-3.6.0
Create a link with command sudo ln -sf ~/Develop/apache-maven-3.6.0/bin/mvn /usr/local/bin/mvn (change version number per your case, if the local bin folder missing, just create it mkdir -p /usr/local/bin).
Check the installation mvn --version
Hope it works for you.
After hundreds updating configure file, now mvn -version can works, share my update and hope it can help you.
fill or update vim ~/.mavenrc(in the beginning, this file isn't exist)
# my MacOS is 10.15+
export Java_HOME=$(/usr/libexec/Java_home)
and then source ~/.mavenrc to let system env effective.
Summary:for my mac system, seems maven couldn't get JAVA_HOME from .bash_profile or .profile, so if you confirm your JAVA_HOME is set correctly and MAVEN_HOME configured, then you can have a try in this way.

JAVA_HOME is not working in maven

java is installed at this path
$ which java
/usr/bin/java
mvn -version is giving this error
$ mvn -version
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE
I have tried some of the solutions that were available online, but those don't work for me. Some of those solutions suggested adding
$export JAVA_HOME = /usr/libexec/java_home
or
$export JAVA_HOME = $(/usr/libexec/java_home)
to below files
~/.bashrc
~/.bash_profile
~/.profile
Also when I try to execute one shell command, it shows me error like
Error: JAVA_HOME is not defined correctly.
CARBON cannot execute /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/bin/java
After struggling for almost a day, I found out that maven is not reading the $JAVA_HOME from either of
~/.bashrc
~/.bash_profile
~/.profile
but it reads $JAVA_HOME from ~/.mavenrc
So finally, when I added
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_141.jdk/Contents/Home
in ~/.mavenrc then got output
mvn -v
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=1024m; support was removed in 8.0
Apache Maven 3.5.0 (ff8f5e7444045639af65f6095c62210b5713f426; 2017-04-03T15:39:06-04:00)
Maven home: /usr/local/Cellar/maven/3.5.0/libexec
Java version: 1.8.0_141, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_141.jdk/Contents/Home/jre
Default locale: en_CA, platform encoding: UTF-8
OS name: "mac os x", version: "10.12.6", arch: "x86_64", family: "mac"
To fixed it, update the JAVA_HOME like following :
$ vim .bash_profile
export JAVA_HOME=$(/usr/libexec/java_home)
$ source .bash_profile
Run Maven again :
$ mvn -version
maven reads JAVA_HOME from ~/.mavenrc. Add path for JAVA_HOME to ~./mavenrc and source it.
$ vim ~/.mavenrc
export JAVA_HOME=$(/usr/libexec/java_home)
$ source .mavenrc
On Ubuntu
I faced a similar problem. I configured $JAVA_HOME in /etc/environment
like JAVA_HOME=PATH_TO_JDK for example JAVA_HOME=/home/max/jdk1.8.0_144
Careful with
White space after path declaration JAVA_HOME=/home/max/jdk1.8.0_144[[_NO_WHITE_SPACE_AFTER_DECLARATION]]
Don't put any quotes, e.g. JAVA_HOME="/home/max/jdk1.8.0_144"
Don't put /bin, e.g. JAVA_HOME=/home/max/jdk1.8.0_144/bin <- This is wrong
Please check once there should be no ';' in JAVA_HOME value, if there is semicolon then it would show above error.
I had
JAVA_HOME
set but did not export it and maven was not picking up the correct JAVA_HOME.
Once I exported JAVA_HOME then it got resolved. Do not forget to export JAVA_HOME so that the variable is available to child processes (UNIX* like OS)
export JAVA_HOME=/Library/Java/JavaVirtualMachines/amazon-corretto-11.jdk/Contents/Home

.Sh script to install java at a specific location

I am using following command to install java 8 in my ubuntu 32 bit matchine.I am using .sh file to run these commands-
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-set-default
read -t 10
It's working fine but I am facing two problems
It set default location in environment variable of java(I want to install in my specific direcory like home/abc/ something and set enviornment variable according to that)
I want to pause script for 10 seconds at the end to check console.
I just want to check either my enviornment variable is set or not I am using this comamnd in my .sh file
export PATH=$PATH:$(pwd)/Linux_32/Software/jdk1.8.0_20/bin
and when I open terminal and check
java -version
It does not show me anything that is why I what to check is there anything problem with java installation. but each time .sh terminal get closed
It appears you are trying to run java -version after the script but the modified PATH environment variable does not persist beyond the script. They're running in different shells. To validate, run printenv PATH and you'll notice the jdk path is not appended.
You could try running java -version within the script or add the jdk to your PATH after the script runs, e.g. in your .profile or .bashrc.

How do I check if the Java JDK is installed on Mac?

How do you check if Java SDK is installed on a Mac?
Is there a command line for this?
javac -version in a terminal will do
You can leverage the java_home helper binary on OS X for what you're looking for.
To list all versions of installed JDK:
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
1.8.0_51, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home
1.7.0_79, x86_64: "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
To request the JAVA_HOME path of a specific JDK version, you can do:
$ /usr/libexec/java_home -v 1.7
/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
$ /usr/libexec/java_home -v 1.8
/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home
You could take advantage of the above commands in your script like this:
REQUESTED_JAVA_VERSION="1.7"
if POSSIBLE_JAVA_HOME="$(/usr/libexec/java_home -v $REQUESTED_JAVA_VERSION 2>/dev/null)"; then
# Do this if you want to export JAVA_HOME
export JAVA_HOME="$POSSIBLE_JAVA_HOME"
echo "Java SDK is installed"
else
echo "Did not find any installed JDK for version $REQUESTED_JAVA_VERSION"
fi
You might be able to do if-else and check for multiple different versions of java as well.
If you prefer XML output, java_home also has a -X option to output in XML.
$ /usr/libexec/java_home --help
Usage: java_home [options...]
Returns the path to a Java home directory from the current user's settings.
Options:
[-v/--version <version>] Filter Java versions in the "JVMVersion" form 1.X(+ or *).
[-a/--arch <architecture>] Filter JVMs matching architecture (i386, x86_64, etc).
[-d/--datamodel <datamodel>] Filter JVMs capable of -d32 or -d64
[-t/--task <task>] Use the JVM list for a specific task (Applets, WebStart, BundledApp, JNI, or CommandLine)
[-F/--failfast] Fail when filters return no JVMs, do not continue with default.
[ --exec <command> ...] Execute the $JAVA_HOME/bin/<command> with the remaining arguments.
[-R/--request] Request installation of a Java Runtime if not installed.
[-X/--xml] Print full JVM list and additional data as XML plist.
[-V/--verbose] Print full JVM list with architectures.
[-h/--help] This usage information.
Type in a terminal:
which javac
It should show you something like
/usr/bin/javac
Below command worked out pretty good:
javac -version
I also manually verified by navigating to the Java Folder on my Mac
/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk
/usr/bin/java_home tool returns 1 if java not installed.
So you can check if java is installed by the next way:
/usr/libexec/java_home &> /dev/null && echo "installed" || echo "not installed"
Open terminal.
run command to see:
javac -version
Also you can verify manually by going to the specific location and then check. To do this run below command in the mac terminal
cd /Library/Java/JavaVirtualMachines/
Then run ls command in the terminal again. Now you can see the jdk version & package if exists in your computer.
If you are on Mac OS Big Sur, then you probably have a messed up java installation.
I found info on how to fix the issue with this article:
https://knasmueller.net/how-to-install-java-openjdk-15-on-macos-big-sur
Download the .tar.gz file of the JDK on https://jdk.java.net/15/
Navigate to the download folder, and run these commands (move the .tar.gz file, extract it and remove it after extraction):
sudo mv openjdk-15.0.2_osx-x64_bin.tar.gz /Library/Java/JavaVirtualMachines/
cd /Library/Java/JavaVirtualMachines/
sudo tar -xzf openjdk-15.0.2_osx-x64_bin.tar.gz
sudo rm openjdk-15.0.2_osx-x64_bin.tar.gz
Note: it might be 15.0.3 or higher, depending on the date of your download.
run /usr/libexec/java_home -v15 and copy the output
add this line to your .bash_profile or .zshrc file, depending on which shell you are using. You will probably have only one of these files existing in your home directory (~/.bash_profile or ~/.zshrc).
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-15.0.2.jdk/Contents/Home
save the changes and make them effective right away by running:
source ~/.bash_profile or source ~/.zshrc
check that java is working - run java -v
Just type javac. If it is installed you get usage information, otherwise it would just ask if you would like to install Java.
Make sure you correctly define the project's JDK and restart IntelliJ (full restart).
On MAC find your JDK path by executing the command.
/usr/libexec/java_home

Resources