Unable to setup Maven in windows 7 - java

I have installed JDk 8 and even dowloaded apache maven 3.3.3.Also I have set path for both Java and Maven but when I tried executing mvn --version command in command prompt then it is showing an error that "'mvn' is not recognized as internal or external command operable program or batch file"

Please follow the below steps in order to setup Maven on windows machine.
Please make sure to change your maven downloaded version. Hope you extracted in below location or you can do in any location and make sure to give correct path.
C:\Program Files\Apache Software Foundation\apache-maven-3.3.3
Then you need to set M2_HOME, M2, MAVEN_OPTS to environment variables.
M2_HOME=C:\Program Files\Apache Software Foundation\apache-maven-3.3.3
M2=%M2_HOME%\bin
MAVEN_OPTS=-Xms256m -Xmx512m
Done !!
Simply open new command prompt and check mvn -version

Assuming you are running on Windows, just define your M2_HOME variable to point to your maven installation folder and add %M2_HOME%\bin to your PATH variable.
This is a pretty decent tutorial: http://www.avajava.com/tutorials/lessons/what-is-maven-and-how-do-i-install-it.html

If you've followed the official installation instruction and it works when you specify mvn.bat, but not mvn then your PATHEXT environment variable needs to be adjusted:
set PATHEXT=.COM;.EXE;.BAT;.CMD
The command above is usually the default.

Steps to set-up Maven
Make sure JDK is installed, and JAVA_HOME variable is added as Windows environment variable.
Download the Maven zip file, for example : apache-maven-3.3.9-bin.zip. Unzip it to the folder where you want.
Assume you unzip to this folder – C:\Program Files\apache-maven-3.3.9
That’s all, just folders and files, installation is NOT required.
Add both M2_HOME and MAVEN_HOME variables in the Windows environment, and point it to your Maven folder.
Edit PATH variable, append Maven bin folder – %M2_HOME%\bin, so that you can run the Maven’s command everywhere.
Run mvn –version in the command prompt, if the below message is displayed the maven setup is done.
ENJOY CODING!!!

Related

how do i solve this Error injecting constructor, java.lang.NoClassDefFoundError: javax/crypto/SecretKey

i also tried the below mentioned steps:
check maven version by mvn -version in cmd
check prerequisites such as gmconstant.js, application.prop, jboss-deploymnet_structure.xml,pom file with others or follow the env setup document
check java version as 1.8.0_161 and ur maven version should be 3.6.2 or 3.6.3
if maven is not deploying try executing this command
Call mvn -Dbuild.version=Local -Doutput.dir="C:\jboss-eap-7.0\standalone\deployments" clean install
try getting the entire project folder from others and check in your environment
if setting your environmental variables, then give SET PATH=C in command prompt as administrator
deleting the files unders .m2 folder /repository
C:\Users\asophia.m2\repository
also added the below mention paths in environment variables
C:\Oracle\Middleware\jdk160_18\bin
C:\Program Files\Java\jre1.8.0_161
C:\Program Files\Java\jdk1.8.0_161
also set the path C:\Tools\apache-maven-3.6.2\bin in user variable
You have to add the encryption jar in C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext or whatever jdk you are using and then register it as well.
Since you are using Oracle jdk, you probably need their jar (JCE).
https://www.oracle.com/java/technologies/java-archive-downloads-java-plat-downloads.html#JCE-1_2_2-G-JS
Quoting the documentation:
Installing Providers
In order to be used, a cryptographic provider must first be installed, then registered either statically or dynamically.
Static Registration
The configuration file is located in the following location:
Unix: /lib/security/java.security
Windows: \lib\security\java.security
You can check the documentation for a well detailed explanation:
https://docs.oracle.com/javase/7/docs/technotes/guides/security/crypto/CryptoSpec.html

VS Code Showing 'mvn' is not recognized as an internal or external command

I'm trying to create a maven project with VS Code but when I run the command it says :
'mvn' is not recognized as an internal or external command,operable program or batch file.
but mvn -version is running on command prompt
Environment varaible for User :
MAVEN_JOME : C:\apache-maven-3.6.1,
M2_HOME : C:\apache-maven-3.6.1,
JAVA_HOME : C:\Program Files\Java\jdk1.8.0_212\jre and
System Variables
path is set to C:\apache-maven-3.6.1\bin, C:\Program Files\Java\jdk1.8.0_212\bin for maven and java respectively.
The command I'm running to create the project is:
mvn archetype:generate -DgroupId=com.cs.test-project -DartifactId=test-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false The Reference to Command
And the VS Code Reference to Command
The same command is running in Command prompt and it created the project successfully on Desktop.
I fixed this problem by simply restarting VSCode as I had set my PATH variable while my VSCode was running so the changes were not reflected to the VSCode integrated terminal until I restarted it.
It's kindy counterintuitive as path has to be pointed to the actual mvn command, instead to a M2_PATH folder. Also once properly pointed, a new error will be shown if your environment is missing proper jdk within JAVA_HOME. The error is trown by maven. Maven plugin is kinda stupid as it will ignore your default JDK configured within settings.json (java.home or/and java.configuration.runtimes properties) and will happly NOT set java for maven. You have to configure it specificly for maven plugin as this:
"maven.executable.path": "c:\\apache-maven-3.8.1\\bin\\mvn",
"maven.terminal.customEnv": [{
"environmentVariable": "JAVA_HOME",
"value": "c:\\openjdk-1.8.0_232-redhat",
}]
Of course, both paths should be pointed to proper folders/files in your environment.
The way I fixed was by changing the exec path in Vs Code settings from CMD to Powershell.
Open
settings -> features -> terminal
Change the windows exec path from cmd to where you have PowerShell.
For example: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Windows exec setting
On Tuesday Oct. 25, 2022 while trying to solve the same problem, I went through all of these previous solutions for Windows and finally had to resort to the official installation docs:
Installing Apache Maven
Unzipped the download and located the bin directory and manually added that directory location to my: System Properties>Advanced>Environment Variables>'Path'
For good measure, restart the computer.

mvn could not find or load main class org.codehaus.plexus.classworlds.launcher.launcher [duplicate]

I have installed a latest maven-3.0.4 on Windows 7:
The installation details are as follows:
Installation Path :
C:\apache-maven-3.0.4
Environment Variables are:
M2_HOME C:\apache-maven-3.0.4\apache-maven\src
JAVA_HOME C:\Program Files\Java\jdk-1.7.0_04
Path variables added are:
%M2_HOME%\bin;%JAVA_HOME%\bin;
In the command window it shows it like this:
C:\>java -version
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b22)
Java HotSpot(TM) Client VM (build 23.0-b21, mixed mode, sharing)
C:\>mvn -version
Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
This is the only version on maven installed on my PC and the solution given on many blogs referring to the deletion of the previous M2_HOME environment variable is not valid.
I have read and tried all the solutions given at blogs such as :
oracle blog,
stackoverflow question,
another stack question,
some blog,
But I'm still not able to get to it. What I might be missing in this whole thing?
I hit this problem too, and found this article. For Maven3, changing my environment variable name from M2_HOME to M3_HOME did the trick. I am on a Mac running OSX 10.9 with JDK 1.7.
Note: Please delete M2_HOME, if already set. Eg: unset M2_HOME.
Even though the question is answered I would like to add that, if you are getting the above mentioned error, be sure that you have downloaded the Binary file.
The source file should only be downloaded if you are an advanced user and that you know how to deal with it.
I have had quite a share of people downloading the wrong file, seniors and juniors
I was having this same problem and was able to resolve it by carefully redoing the Environment Variables:
M2_HOME
M2
JAVA_HOME
Also, I made them all System Variables, not User Variables like the Maven instructions say. When you
echo %Path%
Make sure you can see the %M2% and %JAVA_HOME% variables completely expanded, i.e. :
C:\Users\afairchild>echo %Path%
C:\Program Files\Apache Software Foundation\apache-maven-3.0.4\bin;C:\Program Files\Java\jdk1.7.0_09\bin; [etc]
I believe this error caused because of downloading SRC instead of BINARY from Maven site. Please make sure to download Binary zip.
Because the below path, you will get only when you download SRC:
M2_HOME C:\apache-maven-3.0.4\apache-maven\src
Had this issue on two different Ubuntu 12.04 installs, despite the installs being done by apt-get. Issue was M2_HOME.
Fixed with:
export M2_HOME=/usr/share/maven
It sounds like you installed (extracted) the source files instead of the binaries based on your path information. Try installing the binaries instead and following the other posters answer.
Well, I had this problem and after seeing this post and particularly khmarbaise answer I noticed that M2_HOME was
D:\workspace\apache-maven-3.1.0-bin\apache-maven-3.1.0\bin
and then I chaged it to
D:\workspace\apache-maven-3.1.0-bin\apache-maven-3.1.0
I would like to mention that I use windows 7 (x64)
The solution for later versions of Maven is straight-forward. I am on OS X ElCap, 10.11.6 and upgraded to Maven 3.3.9. I had the same problem with error "Could not find ...org.codehaus.plexus...". The link provided here offered the solution in a comment by McKamey - simply delete M2_HOME (unset M2_HOME). Once I tried that, it all worked as expected.
This can be confirmed by visiting the Maven install page: "Add the bin directory of the created directory apache-maven-3.3.9 to the PATH environment variable" -- no mention of M2_HOME or M3_HOME at all.
For most of the Maven setup issues something like "Could not find or load main class...", start-with below steps to see if that fixes:
Make sure you unzipped the right archive (BINARY archive and not SOURCE archive)
Remove all user and system variables related to Maven (ex. M2_HOME,M2_OPTS etc.)
Make sure JAVA_HOME system variable is setup (ex. "C:\Program Files\Java\jdk1.8.0_172")
Make sure java bin location is added in "path" system variable (ex. "%JAVA_HOME%\bin")
Make sure maven bin location is added in "path" system variable (ex. "C:\MyInstalls\apache-maven-3.5.4\bin")
then...
Verify java is setup (at commandprompt : java -version)
Verify maven is setup (at commandprompt : mvn --version)
Open a new terminal and do the followin
M2_HOME=/Users/macbook/apache-maven-3.6.1 //Set where maven is
M2=$M2_HOME/bin //Set home as bin
export PATH=$M2:$PATH //Place the new path
Then type
mvn -version
You can set this in ./bash_profile to do it automatically each time you run the terminal
You should change the location of the M2_HOME into the following:
set M2_HOME=C:\apache-maven-3.0.4\apache-maven
Furthermore the installation of the JDK looks more a JRE instead of JDK. For Maven you need JDK and NOT JRE.
I came across a similar problem on my mac OSX. After a series of trial and error attempts I finally resolved it.
My ~/.bash_profile looked like this
export M2_HOME=/Users/xyz/maven-3.x/bin
export PATH=$PATH:$M2_HOME
and when I tried to echo M2_HOME from the terminal, it showed me the correct path but when I tried to fire any maven command like mvn clean or mvn install, it always gave the same problem
Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
I solved this issue by changing my M2_HOME to this
export M2_HOME=/Users/xyz/maven-3.x
export PATH=$PATH:$M2_HOME/bin
And voila ! It started working ! Just by moving the position of /bin from M2_HOME to in front of the PATH
Just make sure you've downloaded Binary zip archive(apache-maven-3.5.0-bin.zip) instead of Source zip archive. Then add the bin directory of the created directory apache-maven-3.5.0 to the PATH environment variable.
install binary version of maven fixes the issues
apache-maven-3.6.1-bin.zip
I had the same issue. I have Windows xp box and when I would type mvn -version at the command line prompt I got the dreaded error message
"Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/plexus/classworlds/launcher/Launcher"
I confirmed that my M2_HOME variable was set to the path where Maven was installed on pc and that the echo %path% confirmed that Maven was in my path.
I have been searching for a solution for hours when I stumbled on to my solution (I say my solution because I know this probably won't be the solution for everyone that is getting the same error).
I copied the path that was assigned to my M2_HOME variable. I opened a cmd window and typed cd and pasted the path I got from my M2_HOME variable. At that point I knew that the path was correct because the path was displayed in the window. At this point I entered the dir command and to my surprise, I got the error File Not Found.
I went to that path via Explorer and sure enough there were files present. I noticed that the folders were faded out, but I could access them and see the files within each folder (I have admin rights on my pc). I looked at the properties of the parent folder for Maven and saw that the Hidden box was checked. I removed the check and applied and tried my dir command again with success.
Next I tried the mvn –version command again, but this time I got back the expected results.
C:\>mvn -version
Apache Maven 3.0.3 (r1075438; 2011-02-28 11:31:09-0600)
Maven home: C:\Program Files\apache-maven-3.0.3
Java version: 1.5.0_16, vendor: Sun Microsystems Inc.
Java home: C:\Java\jdk1.5.0_16\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows xp", version: "5.1", arch: "x86", family: "windows"
Finally I created a jar and war file and my web app ran successfully on my local Tomcat.
I hope this helps some of you out there.
Besides what #khmarbaise has pointed out, I think you have mistyped your JAVA_HOME. If you have installed in the default location, then there should be no "-" (hyphen) between jdk and 1.7.0_04. So it would be
JAVA_HOME C:\Program Files\Java\jdk1.7.0_04
For other people who might run into this, don't forget to check ~/.mavenrc for M2_HOME or JAVA_HOME settings.
Try to download binary zip (for ex. Maven 3.0.5 (Binary zip)) instead of complete source in official maven site.
Also make sure that command line recognizes java and javac commands.
I noticed that Maven Source zip didn't include any libraries at lib folder however Binary zip had them + in boot folder it had plexus-classworlds-2.4.jar. Perhaps the problem was with the absence of these libraries. Anyway it helped me so my M2_HOME is: C:\Program Files\Java\apache-maven-3.0.5 and at PATH I put: C:\Program Files\Java\apache-maven-3.0.5\bin.
I find this issue in my centOS is caused by "Oracle Java is replace by gcj", after change default java to "Oracle Java", the issue is resolved.
alternatives --config java
There are 2 programs which provide 'java'.
Selection Command
-----------------------------------------------
* 1 /usr/lib/jvm/jre-1.5.0-gcj/bin/java
+ 2 /usr/java/jdk1.7.0_67/bin/java
It look like that you have installed Source files(Because src only comes in Source Files and we don't need it). Try to install Binary Files from
there.
And then set environment variables as described
there.
This worked for me. And I am sure it will also work for you.
I think you download the wrong version.
I meet this problem just now, no method work after searching and searching.
Finally, I found that maven I downloaded is Source zip archive.
After I change to Binary zip archive, everything go to be fine.
Me too faced the similar issue. But in my case I used apache-maven-3.3.3-src folder in path variables. Later I corrected those with correct path of folder apache-maven-3.3.3-bin. This resolved the issue. Am not telling that is the same error reported here but this way also you can get this error and rectify it. That is what I am trying to say here.
Exactly the same error may appear even with correct environment variable settings, if you copy ONLY bin directory to the installation directory.
It make which work finely, and novices get stuck.
Next to the maybe useful, but maybe too symptomatic answers, here is one which tries to help to find the cause of the problem.
Maven is a command-line java tool. That means, it is not a standalone binary, it is a collection of java .jars, interpreted by a jvm (java.exe on windows, java on linux).
The mvn command, is a script. On windows, it is a script called mvn.cmd and on linux, it is a shell script. Thus, if you write: mvn install, what will happen:
a command interpreter (/bin/sh or cmd.exe) is called for the actual invoking script
this script sets the needed environment variables
and finally, it calls a java interpreter with the the required classpath which contain the maven functionality.
The problem is with (2). Fortunately, this script is simply, very simple. For a java programmer it shouldn't be a big trouble to debug a script around 20 lines, even if it is a little bit alien language.
On linux, you can debug shellscripts giving the -x flag to your shell interpreter (which is most probably bash). On windows, you have to find some other way to debug a cmd.exe script. So, instead of mvn install, give the command bash -x mvn install.
The result be like:
+ '[' -z '' ']'
+ '[' -f /etc/mavenrc ']'
+ '[' -f /home/picsa/.mavenrc ']'
+ cygwin=true
+ darwin=false
...not so many things...
+ MAVEN_PROJECTBASEDIR='C:\peter\bin'
+ export MAVEN_PROJECTBASEDIR
+ MAVEN_CMD_LINE_ARGS=' '
+ export MAVEN_CMD_LINE_ARGS
+ exec '/cygdrive/c/Program Files/Java/jdk1.8.0_66/bin/java' -classpath 'C:\peter/boot/plexus-classworlds-*.jar' '-Dclassworlds.conf=C:\peter/bin/m2.conf' '-Dmaven.home=C:\peter' '-Dmaven.multiModuleProjectDirectory=C:\peter\bin' org.codehaus.plexus.classworlds.launcher.Launcher
Fehler: Hauptklasse org.codehaus.plexus.classworlds.launcher.Launcher konnte nicht gefunden oder geladen werden
At the end, you can easily test, which environment variable gone bad, and you can very easily fix your script (or set it what is needed).
I had this problem when I used Maven 3.5.4 on OpenJDK 11 on Ubuntu. The OpenJDK 11 on Ubuntu is actually still a JDK10:
$ ls -al /etc/alternatives/java
lrwxrwxrwx 1 root root 43 Aug 24 04:54 /etc/alternatives/java -> /usr/lib/jvm/java-11-openjdk-amd64/bin/java
$ java --version
openjdk 10.0.2 2018-07-17
OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.3)
OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.3, mixed mode)
I installed OpenJDK from Oracle into /opt/jdk-11.0.1 and run Maven like this:
JAVA_HOME=/opt/jdk-11.0.1 mvn
It now works like a charm.
I had a problem with surefire plugin itself. Going back to version 2.6 worked for me. Version 2.18/20/22.1 gave me the error.
Now I tried version 3.0.0-M1 of surefire plugin and it works.
So something is wrong in surefire plgin between version 2.6 and 3.0.0. I assume there is something hardcoded as default which should not.
For me, funny as it sounds, it helped just restarting eclipse...
This worked for me:
Remove all Mavin references in Environment Variables
Download the Binary from mavin
Unzip it to where you'd like ex: C:\apache-maven-3.6.0
Go to Environment variables and add to System variable path "C:\apache-maven-3.6.0\bin"
start command prompt as Administrator
check version with: mvn -v
CMD Result:
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T20:41:47+02:00)
Maven home: C:\apache-maven-3.6.0\bin..
I also faced the following Error in my system (Mac)
Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
After doing some random browsing, I came across the link "http://maven.apache.org/install.html" that says "JAVA_HOME" should be set to "/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre".
When I changed "JAVA_HOME" as stated above in ".bash_profile", "mvn" command started working but "javac -version" command stopped working.
When I typed "javac -version" command, I got the following error
Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/bin/javac" (-1)
Hence I rolled back my "JAVA_HOME" to "/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home" in ".bash_profile" and added the following line at the top in "mvn" script
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre
Now both "mvn" and "javac" commands worked properly, but after careful observation of the mvn script, I could not make the difference between the following commands
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java -classpath /Users/venkatarajeevmandava/Documents/Maven/apache-maven-3.6.1/boot/plexus-classworlds-2.6.0.jar -Dclassworlds.conf=/Users/venkatarajeevmandava/Documents/Maven/apache-maven-3.6.1/bin/m2.conf -Dmaven.home=/Users/venkatarajeevmandava/Documents/Maven/apache-maven-3.6.1 -Dlibrary.jansi.path=/Users/venkatarajeevmandava/Documents/Maven/apache-maven-3.6.1/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/Users/venkatarajeevmandava/Documents/Maven/apache-maven-3.6.1/bin org.codehaus.plexus.classworlds.launcher.Launcher
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/bin/java -classpath /Users/venkatarajeevmandava/Documents/Maven/apache-maven-3.6.1/boot/plexus-classworlds-2.6.0.jar -Dclassworlds.conf=/Users/venkatarajeevmandava/Documents/Maven/apache-maven-3.6.1/bin/m2.conf -Dmaven.home=/Users/venkatarajeevmandava/Documents/Maven/apache-maven-3.6.1 -Dlibrary.jansi.path=/Users/venkatarajeevmandava/Documents/Maven/apache-maven-3.6.1/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/Users/venkatarajeevmandava/Documents/Maven/apache-maven-3.6.1/bin org.codehaus.plexus.classworlds.launcher.Launcher
In the above the first command caused the following error
Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
while the second command worked fine.
Please Note that both the above paths have "java" command while one is from "jre" the other is from "jdk"
Other global variables are as following in ".bash_profile"
export M2_HOME=/Users/venkatarajeevmandava/Documents/Maven/apache-maven-3.6.1
export PATH=$PATH:$M2_HOME/bin
Was able to solve this issue by deleting the downloaded maven in my machine ( /Users/kkohli/Desktop/Personal/Code/Java/apache-maven-3.6.3 ) and re-downloading the binary version from the apache site. Did not modify any other bashprofile file etc ( My M2_HOME, JAVA_HOME etc are set inside my bashprofile)

Cannot get Maven working on Windows 7 [duplicate]

I just installed Maven and added the \bin directory of maven to my path variables. When I try to use the mvn command in the Command Prompt I just get a message:
mvn: command not found
Everything else I found on here did not help yet.
Edit:
I used https://maven.apache.org/install.html to install maven.
SET PATH=%PATH%;C:\Program Files\Maven\apache-maven-3.5.0\bin\mvn.cmd
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
You have included the file in the path:
C:\Program Files\Maven\apache-maven-3.5.0\bin\mvn.cmd
That is not good. The PATH environment variable should only include a path to where files, like exe and cmd's can be found.
Adapt your PATH to read like this:
C:\Program Files\Maven\apache-maven-3.5.0\bin
(so remove the \mvn.cmd). Make sure to start a new command prompt to verify if your path settings are correct.
See How can I set user environmental variables (such as PATH) from a non-administrator account on Windows 7 to find the correct Windows dialog to adapt the settings among many more.
Following this tutorial by mkyong, I was able to get this to work on Windows 10 (v10.0.15063):
Install JDK and setup JAVA_HOME system variable
Download Maven zip, extract it and setup M2_HOME and MAVEN_HOME system variables to point to root maven folder (without \bin)
Update PATH system variable to include %M2_HOME%\bin (this is what will let you run "mvn" in Command Prompt).
Open Command Prompt (cmd.exe) and execute mvn -version
You can download Maven (apache-maven-3.5.0-bin.zip) here, if you don't have it already.
The Java SDK (jdk-8u144-windows-x64.exe) can be downloaded from Oracle here.
This is my working maven configuration on Windows 10. Was more cumbersome to configure on W10 than on WXP or W7.
I've faced the same problem. I installed Maven and added the \bin directory of maven to my path variables in System Variables, so I can only use MAVEN commands using admin rights (run cmd in windows as administrator)
I solved this by creating all under User variables (including the PATH variable).

Maven error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher

I have installed a latest maven-3.0.4 on Windows 7:
The installation details are as follows:
Installation Path :
C:\apache-maven-3.0.4
Environment Variables are:
M2_HOME C:\apache-maven-3.0.4\apache-maven\src
JAVA_HOME C:\Program Files\Java\jdk-1.7.0_04
Path variables added are:
%M2_HOME%\bin;%JAVA_HOME%\bin;
In the command window it shows it like this:
C:\>java -version
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b22)
Java HotSpot(TM) Client VM (build 23.0-b21, mixed mode, sharing)
C:\>mvn -version
Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
This is the only version on maven installed on my PC and the solution given on many blogs referring to the deletion of the previous M2_HOME environment variable is not valid.
I have read and tried all the solutions given at blogs such as :
oracle blog,
stackoverflow question,
another stack question,
some blog,
But I'm still not able to get to it. What I might be missing in this whole thing?
I hit this problem too, and found this article. For Maven3, changing my environment variable name from M2_HOME to M3_HOME did the trick. I am on a Mac running OSX 10.9 with JDK 1.7.
Note: Please delete M2_HOME, if already set. Eg: unset M2_HOME.
Even though the question is answered I would like to add that, if you are getting the above mentioned error, be sure that you have downloaded the Binary file.
The source file should only be downloaded if you are an advanced user and that you know how to deal with it.
I have had quite a share of people downloading the wrong file, seniors and juniors
I was having this same problem and was able to resolve it by carefully redoing the Environment Variables:
M2_HOME
M2
JAVA_HOME
Also, I made them all System Variables, not User Variables like the Maven instructions say. When you
echo %Path%
Make sure you can see the %M2% and %JAVA_HOME% variables completely expanded, i.e. :
C:\Users\afairchild>echo %Path%
C:\Program Files\Apache Software Foundation\apache-maven-3.0.4\bin;C:\Program Files\Java\jdk1.7.0_09\bin; [etc]
I believe this error caused because of downloading SRC instead of BINARY from Maven site. Please make sure to download Binary zip.
Because the below path, you will get only when you download SRC:
M2_HOME C:\apache-maven-3.0.4\apache-maven\src
Had this issue on two different Ubuntu 12.04 installs, despite the installs being done by apt-get. Issue was M2_HOME.
Fixed with:
export M2_HOME=/usr/share/maven
It sounds like you installed (extracted) the source files instead of the binaries based on your path information. Try installing the binaries instead and following the other posters answer.
Well, I had this problem and after seeing this post and particularly khmarbaise answer I noticed that M2_HOME was
D:\workspace\apache-maven-3.1.0-bin\apache-maven-3.1.0\bin
and then I chaged it to
D:\workspace\apache-maven-3.1.0-bin\apache-maven-3.1.0
I would like to mention that I use windows 7 (x64)
The solution for later versions of Maven is straight-forward. I am on OS X ElCap, 10.11.6 and upgraded to Maven 3.3.9. I had the same problem with error "Could not find ...org.codehaus.plexus...". The link provided here offered the solution in a comment by McKamey - simply delete M2_HOME (unset M2_HOME). Once I tried that, it all worked as expected.
This can be confirmed by visiting the Maven install page: "Add the bin directory of the created directory apache-maven-3.3.9 to the PATH environment variable" -- no mention of M2_HOME or M3_HOME at all.
For most of the Maven setup issues something like "Could not find or load main class...", start-with below steps to see if that fixes:
Make sure you unzipped the right archive (BINARY archive and not SOURCE archive)
Remove all user and system variables related to Maven (ex. M2_HOME,M2_OPTS etc.)
Make sure JAVA_HOME system variable is setup (ex. "C:\Program Files\Java\jdk1.8.0_172")
Make sure java bin location is added in "path" system variable (ex. "%JAVA_HOME%\bin")
Make sure maven bin location is added in "path" system variable (ex. "C:\MyInstalls\apache-maven-3.5.4\bin")
then...
Verify java is setup (at commandprompt : java -version)
Verify maven is setup (at commandprompt : mvn --version)
Open a new terminal and do the followin
M2_HOME=/Users/macbook/apache-maven-3.6.1 //Set where maven is
M2=$M2_HOME/bin //Set home as bin
export PATH=$M2:$PATH //Place the new path
Then type
mvn -version
You can set this in ./bash_profile to do it automatically each time you run the terminal
You should change the location of the M2_HOME into the following:
set M2_HOME=C:\apache-maven-3.0.4\apache-maven
Furthermore the installation of the JDK looks more a JRE instead of JDK. For Maven you need JDK and NOT JRE.
I came across a similar problem on my mac OSX. After a series of trial and error attempts I finally resolved it.
My ~/.bash_profile looked like this
export M2_HOME=/Users/xyz/maven-3.x/bin
export PATH=$PATH:$M2_HOME
and when I tried to echo M2_HOME from the terminal, it showed me the correct path but when I tried to fire any maven command like mvn clean or mvn install, it always gave the same problem
Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
I solved this issue by changing my M2_HOME to this
export M2_HOME=/Users/xyz/maven-3.x
export PATH=$PATH:$M2_HOME/bin
And voila ! It started working ! Just by moving the position of /bin from M2_HOME to in front of the PATH
Just make sure you've downloaded Binary zip archive(apache-maven-3.5.0-bin.zip) instead of Source zip archive. Then add the bin directory of the created directory apache-maven-3.5.0 to the PATH environment variable.
install binary version of maven fixes the issues
apache-maven-3.6.1-bin.zip
I had the same issue. I have Windows xp box and when I would type mvn -version at the command line prompt I got the dreaded error message
"Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/plexus/classworlds/launcher/Launcher"
I confirmed that my M2_HOME variable was set to the path where Maven was installed on pc and that the echo %path% confirmed that Maven was in my path.
I have been searching for a solution for hours when I stumbled on to my solution (I say my solution because I know this probably won't be the solution for everyone that is getting the same error).
I copied the path that was assigned to my M2_HOME variable. I opened a cmd window and typed cd and pasted the path I got from my M2_HOME variable. At that point I knew that the path was correct because the path was displayed in the window. At this point I entered the dir command and to my surprise, I got the error File Not Found.
I went to that path via Explorer and sure enough there were files present. I noticed that the folders were faded out, but I could access them and see the files within each folder (I have admin rights on my pc). I looked at the properties of the parent folder for Maven and saw that the Hidden box was checked. I removed the check and applied and tried my dir command again with success.
Next I tried the mvn –version command again, but this time I got back the expected results.
C:\>mvn -version
Apache Maven 3.0.3 (r1075438; 2011-02-28 11:31:09-0600)
Maven home: C:\Program Files\apache-maven-3.0.3
Java version: 1.5.0_16, vendor: Sun Microsystems Inc.
Java home: C:\Java\jdk1.5.0_16\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows xp", version: "5.1", arch: "x86", family: "windows"
Finally I created a jar and war file and my web app ran successfully on my local Tomcat.
I hope this helps some of you out there.
Besides what #khmarbaise has pointed out, I think you have mistyped your JAVA_HOME. If you have installed in the default location, then there should be no "-" (hyphen) between jdk and 1.7.0_04. So it would be
JAVA_HOME C:\Program Files\Java\jdk1.7.0_04
For other people who might run into this, don't forget to check ~/.mavenrc for M2_HOME or JAVA_HOME settings.
Try to download binary zip (for ex. Maven 3.0.5 (Binary zip)) instead of complete source in official maven site.
Also make sure that command line recognizes java and javac commands.
I noticed that Maven Source zip didn't include any libraries at lib folder however Binary zip had them + in boot folder it had plexus-classworlds-2.4.jar. Perhaps the problem was with the absence of these libraries. Anyway it helped me so my M2_HOME is: C:\Program Files\Java\apache-maven-3.0.5 and at PATH I put: C:\Program Files\Java\apache-maven-3.0.5\bin.
I find this issue in my centOS is caused by "Oracle Java is replace by gcj", after change default java to "Oracle Java", the issue is resolved.
alternatives --config java
There are 2 programs which provide 'java'.
Selection Command
-----------------------------------------------
* 1 /usr/lib/jvm/jre-1.5.0-gcj/bin/java
+ 2 /usr/java/jdk1.7.0_67/bin/java
It look like that you have installed Source files(Because src only comes in Source Files and we don't need it). Try to install Binary Files from
there.
And then set environment variables as described
there.
This worked for me. And I am sure it will also work for you.
I think you download the wrong version.
I meet this problem just now, no method work after searching and searching.
Finally, I found that maven I downloaded is Source zip archive.
After I change to Binary zip archive, everything go to be fine.
Me too faced the similar issue. But in my case I used apache-maven-3.3.3-src folder in path variables. Later I corrected those with correct path of folder apache-maven-3.3.3-bin. This resolved the issue. Am not telling that is the same error reported here but this way also you can get this error and rectify it. That is what I am trying to say here.
Exactly the same error may appear even with correct environment variable settings, if you copy ONLY bin directory to the installation directory.
It make which work finely, and novices get stuck.
Next to the maybe useful, but maybe too symptomatic answers, here is one which tries to help to find the cause of the problem.
Maven is a command-line java tool. That means, it is not a standalone binary, it is a collection of java .jars, interpreted by a jvm (java.exe on windows, java on linux).
The mvn command, is a script. On windows, it is a script called mvn.cmd and on linux, it is a shell script. Thus, if you write: mvn install, what will happen:
a command interpreter (/bin/sh or cmd.exe) is called for the actual invoking script
this script sets the needed environment variables
and finally, it calls a java interpreter with the the required classpath which contain the maven functionality.
The problem is with (2). Fortunately, this script is simply, very simple. For a java programmer it shouldn't be a big trouble to debug a script around 20 lines, even if it is a little bit alien language.
On linux, you can debug shellscripts giving the -x flag to your shell interpreter (which is most probably bash). On windows, you have to find some other way to debug a cmd.exe script. So, instead of mvn install, give the command bash -x mvn install.
The result be like:
+ '[' -z '' ']'
+ '[' -f /etc/mavenrc ']'
+ '[' -f /home/picsa/.mavenrc ']'
+ cygwin=true
+ darwin=false
...not so many things...
+ MAVEN_PROJECTBASEDIR='C:\peter\bin'
+ export MAVEN_PROJECTBASEDIR
+ MAVEN_CMD_LINE_ARGS=' '
+ export MAVEN_CMD_LINE_ARGS
+ exec '/cygdrive/c/Program Files/Java/jdk1.8.0_66/bin/java' -classpath 'C:\peter/boot/plexus-classworlds-*.jar' '-Dclassworlds.conf=C:\peter/bin/m2.conf' '-Dmaven.home=C:\peter' '-Dmaven.multiModuleProjectDirectory=C:\peter\bin' org.codehaus.plexus.classworlds.launcher.Launcher
Fehler: Hauptklasse org.codehaus.plexus.classworlds.launcher.Launcher konnte nicht gefunden oder geladen werden
At the end, you can easily test, which environment variable gone bad, and you can very easily fix your script (or set it what is needed).
I had this problem when I used Maven 3.5.4 on OpenJDK 11 on Ubuntu. The OpenJDK 11 on Ubuntu is actually still a JDK10:
$ ls -al /etc/alternatives/java
lrwxrwxrwx 1 root root 43 Aug 24 04:54 /etc/alternatives/java -> /usr/lib/jvm/java-11-openjdk-amd64/bin/java
$ java --version
openjdk 10.0.2 2018-07-17
OpenJDK Runtime Environment (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.3)
OpenJDK 64-Bit Server VM (build 10.0.2+13-Ubuntu-1ubuntu0.18.04.3, mixed mode)
I installed OpenJDK from Oracle into /opt/jdk-11.0.1 and run Maven like this:
JAVA_HOME=/opt/jdk-11.0.1 mvn
It now works like a charm.
I had a problem with surefire plugin itself. Going back to version 2.6 worked for me. Version 2.18/20/22.1 gave me the error.
Now I tried version 3.0.0-M1 of surefire plugin and it works.
So something is wrong in surefire plgin between version 2.6 and 3.0.0. I assume there is something hardcoded as default which should not.
For me, funny as it sounds, it helped just restarting eclipse...
This worked for me:
Remove all Mavin references in Environment Variables
Download the Binary from mavin
Unzip it to where you'd like ex: C:\apache-maven-3.6.0
Go to Environment variables and add to System variable path "C:\apache-maven-3.6.0\bin"
start command prompt as Administrator
check version with: mvn -v
CMD Result:
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T20:41:47+02:00)
Maven home: C:\apache-maven-3.6.0\bin..
I also faced the following Error in my system (Mac)
Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
After doing some random browsing, I came across the link "http://maven.apache.org/install.html" that says "JAVA_HOME" should be set to "/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre".
When I changed "JAVA_HOME" as stated above in ".bash_profile", "mvn" command started working but "javac -version" command stopped working.
When I typed "javac -version" command, I got the following error
Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/bin/javac" (-1)
Hence I rolled back my "JAVA_HOME" to "/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home" in ".bash_profile" and added the following line at the top in "mvn" script
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre
Now both "mvn" and "javac" commands worked properly, but after careful observation of the mvn script, I could not make the difference between the following commands
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java -classpath /Users/venkatarajeevmandava/Documents/Maven/apache-maven-3.6.1/boot/plexus-classworlds-2.6.0.jar -Dclassworlds.conf=/Users/venkatarajeevmandava/Documents/Maven/apache-maven-3.6.1/bin/m2.conf -Dmaven.home=/Users/venkatarajeevmandava/Documents/Maven/apache-maven-3.6.1 -Dlibrary.jansi.path=/Users/venkatarajeevmandava/Documents/Maven/apache-maven-3.6.1/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/Users/venkatarajeevmandava/Documents/Maven/apache-maven-3.6.1/bin org.codehaus.plexus.classworlds.launcher.Launcher
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/bin/java -classpath /Users/venkatarajeevmandava/Documents/Maven/apache-maven-3.6.1/boot/plexus-classworlds-2.6.0.jar -Dclassworlds.conf=/Users/venkatarajeevmandava/Documents/Maven/apache-maven-3.6.1/bin/m2.conf -Dmaven.home=/Users/venkatarajeevmandava/Documents/Maven/apache-maven-3.6.1 -Dlibrary.jansi.path=/Users/venkatarajeevmandava/Documents/Maven/apache-maven-3.6.1/lib/jansi-native -Dmaven.multiModuleProjectDirectory=/Users/venkatarajeevmandava/Documents/Maven/apache-maven-3.6.1/bin org.codehaus.plexus.classworlds.launcher.Launcher
In the above the first command caused the following error
Error: Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
while the second command worked fine.
Please Note that both the above paths have "java" command while one is from "jre" the other is from "jdk"
Other global variables are as following in ".bash_profile"
export M2_HOME=/Users/venkatarajeevmandava/Documents/Maven/apache-maven-3.6.1
export PATH=$PATH:$M2_HOME/bin
Was able to solve this issue by deleting the downloaded maven in my machine ( /Users/kkohli/Desktop/Personal/Code/Java/apache-maven-3.6.3 ) and re-downloading the binary version from the apache site. Did not modify any other bashprofile file etc ( My M2_HOME, JAVA_HOME etc are set inside my bashprofile)

Categories

Resources