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

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.

Related

Java_home path cannot be set

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

How to install Maven in Mac Catalina?

I just installed Maven via Mac Catalina via command line and mvn -version was showing output. then it went away. Please help.
May be a long post, but in the end you will have a convenient tool to install packages and understanding of how to configure them.
Why maven "disappeared" I have no idea of, so what I would do in this situation:
First of all, I would delete maven manually (find the directory and remove it along with any other files that were setup during maven installation)
Then I would highly recommend using Homebrew - a package manager for macOS
To install Homebrew, open terminal and execute the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Wait for a couple of minutes (a less) until it is installed
Now, that Homebrew is installed, you have a very convenient tool to install stuff on your mac
So, you want to install Maven. You can find Maven on Homebrew
Now you just have to open your terminal again and execute
brew install maven
After a few seconds brew will display the directory it installed Maven in (by default, all Homebrew packages are installed in /usr/local/Cellar/)
You are almost there, now you need to set the environment variable.
As described by Apache, the environment variable needs to be added to the PATH environment variable.
Here I have some uncertainty in terms of what file to use: .bash_profile or zprofile. The confusion is caused by the fact that in latest macOS update (maybe several latest updates) Apple decided to use zsh shell, and so .bash_profile became somewhat functionally equivalent to zprofile. There are many articles on the Internet about what file to use, so you better check them out before proceeding (sorry for not providing links).
On my Catalina 10.15.6 I use .zprofile and everything looks to work perfectly.
Once you decide what file to use, execute the following in the terminal:
nano .zprofile
An editor will open, write this:
export PATH=/usr/local/Cellar/maven/*version*/bin:$PATH
Press Control + X to exit, then Y to save changes and hit Enter to exit the editor
After that you will again be in terminal, where execute:
source .zprofile
To load it. Then close the terminal, open again and check that PATH variable is edited by executing:
env
That's it! Good luck coding!
For MacOs Catalina, below is what worked for me.
Terminal > Vim .zprofile
Add:
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_281.jdk/Contents/Home
export JAVA_HOME
M2_HOME=/Users/username/apache-maven-3.8.1 (This is where my maven folder is.)
export M2_HOME
PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin
export PATH
Terminal > source ~/.bash_profile
Restart Terminal > mvn -version
Output:
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: /Users/username/apache-maven-3.8.1
Java version: 1.8.0_281, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_281.jdk/Contents/Home/jre
Default locale: en_IN, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.7", arch: "x86_64", family: "mac"
username#C02F ~ % java -version
java version "1.8.0_281"
Java(TM) SE Runtime Environment (build 1.8.0_281-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.281-b09, mixed mode)
Did you try executing:
source ~/.zshrc

Trouble Setting Up Maven on Mac OS

I'm never used a mac before and this is the first time I've tried to setup a coding environment. I've gone through multiple of the pages on here that give suggestions as to what is wrong, but still getting mvn command not found
I've set my ~/.bash_profile as below:
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-12.0.2.jdk/Contents/Home
export JAVA_HOME
M2_HOME=/Applications/apache-3.6.1
export M2_HOME
PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin
export PATH
A java -version returns the following
java version "12.0.2" 2019-07-16
Java(TM) SE Runtime Environment (build 12.0.2+10)
Java HotSpot(TM) 64-Bit Server VM (build 12.0.2+10, mixed mode, sharing)
So I believe that to be fine
A echo $M2_HOME returns the following
/Applications/apache-3.6.1
Which from what I've seen would suggest that is also correct.
However, mvn -v returns the following:
-bash: mvn: command not found
I've tried restarting the terminal and source ~/.bash_profile
Any help greatly appreciated
James
A ~/.bash_profile like this works for me:
export JAVA_HOME=`/usr/libexec/java_home -v 12`
export M2_HOME=/Applications/apache-maven-3.6.1
export PATH=$PATH:$M2_HOME/bin
Make sure you have a valid Maven installation under /Applications/apache-maven-3.6.1 which has a bin folder inside with the actual executable.
Hope it helps.
Edit-1
Check the difference between:
/Applications/apache-3.6.1 vs.
/Applications/apache-maven-3.6.1

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

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