1. Under Mac, install Maven with homebrew, install successfully, set up m2_home, use Mvn-version to detect
houenxundemacbook-pro:3.3.9 houenxun$ mvn-version Error: The main class could not be found or could not be loaded Org.codehaus.plexus.classworlds.launcher.Launcher
2. Online to see a bunch of solutions, unclear so, then try to solve their own, first of all, first locate the problem of the script
houenxundemacbook-pro:3.3.9 houenxun$ which mvn/usr/local/bin/mvnhouenxundemacbook-pro:3.3.9 houenxun$ ls-l/usr/ Local/bin/mvnlrwxr-xr-x 1 Houenxun Admin 4 7 15:52/usr/local/bin/mvn. /cellar/maven/3.3.9/bin/mvn
Open MVN File
#!/bin/bashjava_home= "${java_home:-$ (/usr/libexec/java_home)}" exec "/usr/local/cellar/maven/3.3.9/libexec/bin/ MVN "" [Email protected] "
You can see that the real call is
/usr/local/cellar/maven/3.3.9/libexec/bin/mvn
Open the file, the file is longer, locate the last error location
Exec "$JAVACMD" $MAVEN _opts $MAVEN _debug_opts-classpath "${m2_home}"/boot/plexus-classworlds-*.jar "-dclassworlds . conf=${m2_home}/bin/m2.conf ""-dmaven.home=${m2_home} ""-dmaven.multimoduleprojectdirectory=${maven_ Projectbasedir} "${classworlds_launcher}" [Email protected] "
Print a real statement using Echo
exec/library/java/javavirtualmachines/jdk1.8.0_77.jdk/contents/home/bin/java-classpath/usr/local/cellar/maven/ 3.3.9/boot/plexus-classworlds-*.jar-dclassworlds.conf=/usr/local/cellar/maven/3.3.9/bin/m2.conf-dmaven.home=/ Usr/local/cellar/maven/3.3.9-dmaven.multimoduleprojectdirectory=/usr/local/cellar/maven/3.3.9/libexec/bin Org.codehaus.plexus.classworlds.launcher.Launcher
3. Strangely, the boot and bin are not present in the/usr/local/cellar/maven/3.3.9 directory, but there is a/usr/local/cellar/maven/3.3.9/libexec directory
houenxundemacbook-pro:3.3.9 houenxun$ pwd/usr/local/cellar/maven/3.3.9houenxundemacbook-pro:3.3.9 houenxun$ lsinstall_receipt.jsonnoticebinlicensereadme.txtlibexechouenxundemacbook-pro:3.3.9 houenxun$ houenxundemacbook-pro:3.3.9 houenxun$ CD libexec/houenxundemacbook-pro:libexec houenxun$ Lsbinbootconflibhouenxundemacbook-pro:libexec houenxun$
4. Try to copy them out, it's OK.
houenxundemacbook-pro:3.3.9 houenxun$ mvn -versionexec /library/java/javavirtualmachines/ jdk1.8.0_77.jdk/contents/home/bin/java -classpath /usr/local/cellar/maven/3.3.9/boot/ plexus-classworlds-2.5.2.jar -dclassworlds.conf=/usr/local/cellar/maven/3.3.9/bin/m2.conf - dmaven.home=/usr/local/cellar/maven/3.3.9 -dmaven.multimoduleprojectdirectory=/usr/local/cellar/maven/ 3.3.9 org.codehaus.plexus.classworlds.launcher.launcher -versionapache maven 3.3.9 ( bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11t00:41:47+08:00) maven home: /usr/local/ Cellar/maven/3.3.9java version: 1.8.0_77, vendor: oracle corporationjava home:  /LIBRARY/JAVA/JAVAVIRTUALMACHINES/JDK1.8.0_77.JDK/CONTENTS/HOME/JREDEFAULT LOCALE: ZH_CN, platform encoding: UTF-8OS name: "Mac os x", version: "10.11.4", arch: "x86_64", family: "Mac"
5. The problem seems to have been solved, but it is strange that homebrew installed maven has a bug???
I habitually set m2_home, why to set up, is to set maven directory into the execution link directory, but according to the second step
/USR/BIN/MVN is a symbolic link to the MVN command, and with this symbolic link m2_home it will not work. We tried to disable the M2_home environment variable
houenxundemacbook-pro:~ houenxun$ mvn -versionexec /library/java/javavirtualmachines/ jdk1.8.0_77.jdk/contents/home/bin/java -classpath /usr/local/cellar/maven/3.3.9/libexec/boot/ plexus-classworlds-2.5.2.jar -dclassworlds.conf=/usr/local/cellar/maven/3.3.9/libexec/bin/m2.conf - Dmaven.home=/usr/local/cellar/maven/3.3.9/libexec -dmaven.multimoduleprojectdirectory=/users/houenxun org.codehaus.plexus.classworlds.launcher.Launcher -versionApache Maven 3.3.9 ( bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11t00:41:47+08:00) maven home: /usr/local/ Cellar/maven/3.3.9/libexecjava version: 1.8.0_77, vendor: oracle corporationjava home: /Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home/jreDefault locale: zh_cn, platform encoding: utf-8os name: "Mac os x", version: " 10.11.4 ", arch: " x86_64 ", family: "Mac"
Can still be executed, and the path of boot and Lib has changed!
The original version of Maven has no need to configure the M2_home environment variable, and the directory hierarchy has changed, but in order to be compatible with the original old version, the script through the m2_home to select the old and new directory level, Ah, their own superfluous!!!
Error: Unable to find or load main class Org.codehaus.plexus.classworlds.launcher.Launcher troubleshooting