How to change maven home directory? - maven

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

Related

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).

Terminal is not sourcing .bash_profile, but sourcing .profile

I created a .bash_profile and added the following:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home
export M2_HOME=/Users/aastha/apache-maven-3.3.9
export PATH=$PATH:$M2_HOME/bin
When I check echo $PATH, I get the following
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
(i.e) maven path is not imported.
and also mvn -version shows: mvn:command not found
When I manually source using source ~/.bash_profile and then do echo $PATH, I am able to see correct mvn path that I have entered in PATH variable in .bash_profile.
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/aastha/apache-maven-3.3.9/bin
mvn -version shows:
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T22:11:47+05:30)
Maven home: /Users/aastha/apache-maven-3.3.9
Java version: 1.8.0_101, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.11.5", arch: "x86_64", family: "mac"
My terminal does not source .bash_profile until I manually source it using
source ~/.bash_profile
Note: I created a .profile with the similar content and found out in this case mvn -version shows the maven is installed. And terminal is sourcing .profile automatically.
Why is my terminal not able to source .bash_profile automatically
Could somebody please help?
Thanks in advance :D

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.

Maven uses wrong jdk

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

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