Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am running Ubuntu 12.04 and am a Java developer who has recently moved off his desktop and started working on a new laptop. I have a few build issues and am investigating my install of Maven.

I got some help setting up my laptop and find the following Maven configuration confusing. I have Maven installed (by a peer I assume) and running but have no M2_HOME. I would have thought it would be a requirement.

The following is my output when I run mvn --version

Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.7.0_51, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre
Default locale: en_GB, platform encoding: UTF-8 
OS name: "linux", version: "3.5.0-23-generic", arch: "amd64", family: "unix"

None of the following give me anything: printenv | grep "maven", printenv | grep "mvn", printenv | grep "M2".

There is nothing special in ~/.profile or /etc/environment related to Maven.


Can you provide any clues/direction as to why mvn --version in the console gives output?

share|improve this question

3 Answers 3

up vote 1 down vote accepted

When you do not understand something you have to investigate why it works the way it works... What you just did. And it is great!

In the case of Maven on Linux/Ubuntu you find confusing the locations where the software is installed... OK. But you have to get used... That is the way it works.
Maybe you are used to install maven yourselves and in it case you have the control of the location of the installation and you can even use M2_HOME. I will come back later on M2_HOME.

I did the same researches and for me it is not confusing at all... But of course the locations could be unexpected for some people...
I have installed the package maven2 to do the same investigations...

rudy@rudy-Inspiron-530:~$ sudo apt-get install maven2 (lot of output that was discarded)
rudy@rudy-Inspiron-530:~$ whereis mvn
mvn: /usr/bin/mvn /usr/bin/X11/mvn /usr/share/man/man1/mvn.1.gz
rudy@rudy-Inspiron-530:~$ ls -l /usr/bin/mvn
lrwxrwxrwx 1 root root 21 fév 16 08:23 /usr/bin/mvn -> /etc/alternatives/mvn
rudy@rudy-Inspiron-530:~$ ls -l /usr/bin/X11/mvn
lrwxrwxrwx 1 root root 21 fév 16 08:23 /usr/bin/X11/mvn -> /etc/alternatives/mvn
rudy@rudy-Inspiron-530:~$ ls -l /etc/alternatives/mvn
lrwxrwxrwx 1 root root 25 fév 16 08:23 /etc/alternatives/mvn -> /usr/share/maven2/bin/mvn
rudy@rudy-Inspiron-530:~$ ls -l /usr/share/maven2/bin/mvn
-rwxr-xr-x 1 root root 6331 jun 25  2013 /usr/share/maven2/bin/mvn


There are soft links that are used. I see in the path /usr/bin/mvn and /usr/bin/X11/mvn. Then /usr/bin/mvn, /usr/bin/X11/mvn and /etc/alternatives/mvn are ALL soft links.
There are several levels and of course it can confuse you...

The real thing is in /usr/share/maven2/bin/mvn.

rudy@rudy-Inspiron-530:/usr/bin$ file /usr/share/maven2/bin/mvn
/usr/share/maven2/bin/mvn: POSIX shell script, ASCII text executable


The command 'file' returns what thing you have to deal with...
In the case of /usr/share/maven2/bin/mvn. It is shell script !

You made the assumption that JAVA_HOME and M2_HOME and ... must be initialized and it is a false assumption... Those variables can help you and some other softwares to use a specific version of softwares. Some softwares does not even work without some of these variables... But when you are in a terminal (and you use the packages) you don't need those variables ! Everything will work without.

share|improve this answer
    
Thank you for your help. I think this is a well written, explanatory response and is well received. –  Crowie Feb 25 at 13:20

The problem semi-disappeared/was hidden but by some chance I ended up looking at my Java version and someone instructed me to execute this

which java 

I also did which mvn.

Following a few links from here:

/usr/bin

I can see a bunch of links that help me to see what is installed on my machine. If I follow the links in /usr/bin by looking at their targets I end up at a folder /etc/alternatives. In this I presume I see almost everything available to execute on my computer via the console or PATH. From here I can see things about Maven (mvn) and Java (java and javac) and other executable programs. I have no idea what this folder.

The folder containing the executables is here:

/etc/alternatives

So I look all the programs up with this command:

ls -ltra /etc/alternatives | less

Down the end I can see the target of Maven.


Again, all this came from a clue about using which when I had a problem, or some confusion, about my running Java versions:

which <insert executable name here>



There is something in my PATH about Maven but I just wasn't aware of it. As I note on my question above about finding the running version of Java, the contents of the file /etc/environment, which can be used to set environment variables of sort, has an entry that contains the following excerpt:

PATH="/usr/loca...sbin:/usr/bin:/sbi...


/usr/bin So that means, I guess, /usr/bin is on my PATH and /usr/bin/ contains links, and those links point to executables which include Maven, Java and and so on.

share|improve this answer

First, it is not MAVEN_HOME but like it is written into the title M2_HOME... The following assertion is true : the mvn command is in your path... The mvn command will function correctly if you were assigned a home directory...

In the home dir, you will find a directory .m2. In $HOME/.m2 you will find the maven repository and the file settins.xml. You don't need a M2_HOME (tested) but you need a JAVA_HOME...

share|improve this answer
    
So because .m2 is in my home directory it works? –  Crowie Feb 12 at 15:32
    
Yes it is because mvn can retrieve the .m2 directory related to the home directory of the user that everything works as expected... Try to rename .m2 to .m2.disabled... The directory will be recreated like the first time you did a mvn on this machine... –  Rudy Vissers Feb 12 at 15:39
    
Okay but why is Maven executable with no M2_HOME? What is making Maven accessible? –  Crowie Feb 12 at 16:20
    
...and nothing visible on any PATH components –  Crowie Feb 12 at 16:21
    
This is not possible... If you are in a terminal and you type 'mvn' and that bash is able to find the 'mvn' command then 'mvn' has to be in your path... Isn't it ? –  Rudy Vissers Feb 13 at 9:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.