Maven uses wrong jdk - maven

I have env.variable $JAVA_HOME it points to folder with jdk7
but if I execute "mvn -version" I see next
MacBook-Pro-Erik:~ erik$ mvn -version
728-version
Apache Maven 3.1.0 (893ca28a1da9d5f51ac03827af98bb730128f9f2; 2013-06-28 06:15:32+0400)
Maven home: /Users/erik/distribs/maven/apache-maven-3.1.0
Java version: 1.6.0_51, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.8.4", arch: "x86_64", family: "mac"
How to enforce maven to use correct jdk? I have java.lang.UnsupportedClassVersionError becouse of this issue :(

Solved by:
echo JAVA_HOME=`/usr/libexec/java_home -v 1.7` | sudo tee -a /etc/mavenrc

Related

Installing Maven on Red Hat Enterprise Linux release 8.3: no Maven version displayed

I installed OpenJDK 11 and Maven 3.8.1 on Red Hat Enterprise Linux release 8.3 as follows:
yum install java-11-openjdk
cd /opt
wget https://downloads.apache.org/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz
mv apache-maven-3.8.1 /opt/maven
Then I created the maven.sh script to declare JAVA_HOME and M2_HOME environment variables as follows:
vi /etc/profile.d/maven.sh
# added the following content:
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk
export M2_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}
Reloade the shell with source /etc/profile.d/maven.sh.
When checking the installed Maven version, it is not displayed, just the Java's one:
mvn -v
Maven home: /opt/maven
Java version: 11.0.10, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-11-openjdk-11.0.10.0.9-4.el8_3.x86_64
Default locale: en_US, platform encoding: ANSI_X3.4-1968
OS name: "linux", version: "4.18.0-240.15.1.el8_3.x86_64", arch: "amd64", family: "unix"
I hoped to see something like:
Apache Maven 3.8.1 (cecedd343002696d0abb50b32b541b8a6ba2883f)
...
What am I missing? Or everything is correct?
I don't see anything wrong here. I have tried almost the same steps and it worked for me.
Adding those steps below
sudo yum install java-11-openjdk
sudo wget https://downloads.apache.org/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz
sudo tar xvf apache-maven-3.8.1-bin.tar.gz
sudo ln -s apache-maven-3.8.1 maven
sudo vi /etc/profile.d/maven.sh
added the below
export JAVA_HOME={provide the path, where your jdk is}
export M2_HOME=/opt/maven
export PATH=${M2_HOME}/bin:${PATH}
source /etc/profile.d/maven.sh
mvn -version
screenshot of maven version
Hopefully, this will work for you!

What should maven M2_Home be?

I installed maven with sudo apt install maven
Then, from this repo ran mvn clean install.
I got the following error
[ERROR] org.eclipse.xtext.maven.plugin.XtextGeneratorIT Time elapsed: 4.246 s <<< FAILURE!
java.lang.AssertionError:
Maven home not found. Tried to call 'mvn'.
Consider to set the envVar 'M2_HOME' or System property 'maven.home'.
Current settings are: maven.home=null M2_HOME=null
What should my M2_HOME be??? I typed mvn --version to get a clue:
$ mvn --version
Apache Maven 3.6.0
Maven home: /usr/share/maven
Java version: 11.0.7, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_IL, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-109-generic", arch: "amd64", family: "unix"
But I'm not sure what to do now. Any help is appreciated, thanks!
M2_HOME is a home of Maven. It should be the root directory of your maven installation/binaries. It is used by script mvn (correspondingly mvn.bat on Windows).

How to change maven home directory?

I have maven home directory as below,
[root#localhost configuration-simple]# su -c "vi /etc/profile.d/maven.sh"
[root#localhost configuration-simple]# mvn -version
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 19:21:28+0530)
Maven home: /home/kartyk/NetBeansProjects/motown.io/motown-develop/apache-maven-3.0.5
Java version: 1.7.0_51, vendor: Oracle Corporation
Java home: /usr/java/jdk1.7.0_51/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.19.8-100.fc20.x86_64", arch: "amd64", family: "unix"
[root#localhost configuration-simple]#
Now I want to change the Maven home directory to some other folder, how could I do this through command prompt?
I assume you are familiar with basics of your OS.
go to Maven download page and get the latest version
extract it in a directory of your choice (/opt or /usr/local or ...)
set and export the environment variable MAVEN_HOME in your .bashrc
extend and export the environment variable PATH by $MAVEN_HOME/bin

Not sure if JAVA_HOME is set

I have installed Maven on Ubuntu 12.04. The following is the output when I do
$ mvn --version
Listening for transport dt_socket at address: 8787
Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.6.0_38, vendor: Sun Microsystems Inc.
Java home: /usr/lib/jvm/jdk1.6.0_38/jre
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "3.2.0-52-generic", arch: "amd64", family: "unix"
but when I do
$ gedit /etc/environment
the output is
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
also the .bash_rc does not have any entry for JAVA_HOME and there is no .bash_profile file.
My Question
If JAVA_HOME is not set how mvn --version is showing a value of it?
If JAVA_HOME is not set how mvn --version is showing a value of it?
On my system, the mvn program is a shell script, which performs various operations to try to guess a value for JAVA_HOME, if a value is not already set. In particular, it examines the location of the javac program.
However, according to the answer of a related question, what mvn reports as "Java home" is not the value of the JAVA_HOME environment variable: it is the value of the java.home system proeprty
Can be set in /etc/.bash_profile or other system rc files.

cannot find mvn/mvnDebug in mac

i installed apache-maven-3.0.4 on mac 10.6.8, the bin folder structure is like this:
/usr/share/java/maven-3.0.4/bin/
-- m2.conf
-- mvn
-- mvn.bat
-- mvnDebug
-- mvnDebug.bat
-- mvnyjp
if i run 'mvn -v' as non-root user, i get:
-bash: maven: command not found
if i run as a root user, i got:
Maven home: /usr/share/maven
Java version: 1.6.0_29, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.6.8", arch: "x86_64", family: "mac"
the same thing to 'mvnDebug', how can i fix this so that non-root user can access these commands? Thanks
You need to set PATH to include /usr/share/java/maven-3.0.4/bin/. And make sure that the modes the entire tree are something like 755.

Resources