Multiple Maven version

2,315 views
Skip to first unread message

Darly Senecal-Baptiste

unread,
May 15, 2015, 12:13:16 PM5/15/15
to go...@googlegroups.com
Hi All

I have set a main Maven version as system environment variable. And we use it as a main. 

(from Linux's bashrc file)

export JAVA_HOME=/usr/jdk1.7.0_51
export M2_HOME=/jenkins/maven/apache-maven-3.2.3
export MAVEN_OPTS="-Xmx512m -XX:MaxPermSize=128m"
export GO_SERVER_PORT=8153
export PATH=${JAVA_HOME}/bin:${M2_HOME}/bin:${PATH}




However, for one project pipeline I wanted to use another version of maven which is not mentioned in the system environment variable; so I had to mention it into the pipeline level environment variables.


 

Now the situation gets tricky. Running the pipeline, I get the following error

10:43:15.050 [go] overriding environment variable 'JAVA_HOME' with value '/usr/jdk1.6.0_20'
10:43:15.050 [go] overriding environment variable 'M2_HOME' with value '/jenkins/maven/apache-maven-2.2.1'
10:43:15.050 [go] overriding environment variable 'MAVEN_OPTS' with value '-Xmx512m -XX:MaxPermSize=256m'
10:43:15.127 Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/plexus/classworlds/launcher/Launcher
10:43:15.128 Caused by: java.lang.ClassNotFoundException: org.codehaus.plexus.classworlds.launcher.Launcher
10:43:15.128    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
10:43:15.128    at java.security.AccessController.doPrivileged(Native Method)
10:43:15.128    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
10:43:15.129    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
10:43:15.129    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
10:43:15.129    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
10:43:15.175 Could not find the main class: org.codehaus.plexus.classworlds.launcher.Launcher.  Program will exit.
10:43:15.193 [go] Current job status: failed.

The question is how to mention another maven version directory in order that error like this shouldn happen.
Message has been deleted

Darly Senecal-Baptiste

unread,
May 15, 2015, 4:54:35 PM5/15/15
to go...@googlegroups.com
Even if it is a Maven issue, I can recall that other products like Jenkins and Teamcity is able to switch maven versions without any issue.

srinivas upadhya

unread,
May 16, 2015, 1:24:47 AM5/16/15
to Darly Senecal-Baptiste, go...@googlegroups.com

You can set Maven verion by specifying M2_HOME at pipeline/stage/job level. These will override the one set at system level.

Darly Senecal-Baptiste

unread,
May 18, 2015, 4:05:02 PM5/18/15
to srinivas upadhya, go...@googlegroups.com
The problem of using multiple maven version, there are problems for either one or another version.

The reason are the following (based on the experience I passed through)

  • If one of the versions is set as M2_HOME environment variable, then the other will have an impact on others's in case of running the command. And consequently, the affected versions would throw the following  error


  • Could not find the main class: org.codehaus.plexus.classworlds.launcher.Launcher.


In case of using multiple versions of Maven, 

(1) Mentioning the JAVA_HOME and the M2_HOME / M2 and MAVEN_OPTS at environment level environment variable.

(2) Do not use the mvn command, since this command is looking for the system's M2_HOME (I don't know why but i wonder why)

(3) At the system Level, DO NOT set the M2_HOME or M3_HOME (for maven3). If you have it, comment out (in linux). As well in the PATH directory. Do not forget to reload the environment variable path.

(4) Manually, run the command by using the direct path of the command. This is in order to verify that the command is working. 

/path/to/a/maven-version/bin/mvn -version

(5) At the Pipeline JOB task, use the following command 

Command: /bin/sh

Arguments:
 -c
/path/to/a/maven-version/bin/mvn clean package. 


Reply all
Reply to author
Forward
0 new messages