Problems setting up Maven [duplicate] - java

This question already has answers here:
Adding a directory to the PATH environment variable in Windows
(21 answers)
Closed 8 years ago.
I am having difficulties installing Maven.
I have set all the enviromental variables according to this: http://maven.apache.org/download.html
Although I am using windows 7, when I try and run the command mvn --version, I get, mvn is not recognized as an internal or external command etc.
When I run it from within src\bin, I get the error:
Exception in thread "main" java.lang.ClassNotFoundException: org.codehaus.plexus.classworlds.launcher.Launcher
at java.net.URLClassLoader$1.run<URLClassLoader.java:202>
at java.security.AccessController.doPrivleged(Native Method)
...etc
then:
Could not find the main class: org.codehaus.plexus.classworlds.launcher.Launcher.

Check that you don't have an M2_HOME environment variable.

I ended up on this question with the same problem, however, I had committed an elementary mistake of downloading the apache-maven-..*-src.zip instead of the apache-maven-..*-bin.zip
Once I realised that mistake, it was smooth sailing as soon as I corrected it. I suppose the instructions on the download page should be more than adequate

All you should need to do to install and use maven:
1) Download maven 3. The ZIP should be fine. Install it in a known place; I use c:\tools\ as the parent directory but your mileage may vary.
2) Set your PATH to point to the bin directory in the installation directory. If Maven is in c:\tools\maven-3.0.3 (as it is on my system), you'd add c:\tools\maven-3.0.3\bin to PATH:
set PATH=%PATH%;c:\tools\maven-3.0.3
You may also want to set MVN_HOME:
set MVN_HOME=c:\tools\maven-3.0.3
3) start a new command shell (cmd.exe). mvn should work; if not, you've skipped something here or something's badly wrong in your configuration.

blanking out M2_HOME worked for me on Ubuntu. Can test with just: 'export M2_HOME='

Your first problem is because you do not have maven in your PATH.
The second problem is what I had. I had both Maven 2 and 3 on my computer and even though I removed Maven 2 links from my PATH, it was still interfering with my new Maven.
You need to remove or rename the system variable M2_HOME.
1. Right click My Computer -> Properties
2. Advanced system settings
3. Environment Variables
4. Rename or delete M2_HOME

I setup M2_HOME like this:
export M2_HOME="~/app/apache-maven-3.1.1"
and saw the same exception:
Exception in thread "main" java.lang.ClassNotFoundException: org.codehaus.plexus.classworlds.launcher.Launcher`.
I changed to use absolute path and it worked:
export M2_HOME="Users/myaccount/app/apache-maven-3.1.1"
In my case, the M2_HOME env variable wasn't the problem. I think that java and/or mvn startup script doesn't expand the tilde in classpath cmd line args.

This is a question from long ago but recently i encountered this problem. In my case it was because i had M2_HOME set from a previous installation from months ago. I just unset the variable and after that was good to go.

I got the same error
In my case configuration which generate error
export M2_HOME="/home/ashoka/apache-maven-3.0.4/bin/"
PATH=$M2_HOME/bin:$PATH
Working configuration
export M2_HOME="/home/ashoka/apache-maven-3.0.4/"
PATH=$M2_HOME/bin:$PATH
Ashok Kumara

"mvn is not recognized as an internal or external command etc." means you haven't set your environment variable in windows. Read the whole http://maven.apache.org/download.html :-)

Do you have maven 2 also installed?
I found one link in searching, see if it helps
http://blogs.oracle.com/sreekanth/entry/java_lang_noclassdeffounderror_org_codehaus
and also double check your environment variables to make sure you have set all the variables mentioned in the doc.
For this error "mvn is not recognized as an internal or external command", add src/bin folder in 'path' environment variable.

Like Joseph Ottinger said, you have to put Maven installation directory to your PATH environment variables or User variables. You can edit user variables by running command "rundll32 sysdm.cpl,EditEnvironmentVariables" without quotes.
First add new variable called MAVEN_HOME and for it's value Mavens installation directory ie. c:\tools\maven-3.0.3\ then edit PATH variable and add end of the value ;%MAVEN_HOME%\bin (notice semicolon)
After re-login or opening new command prompt mvn command should work perfectly.

Some people seem to have trouble with adding Maven bin folders to the System PATH vs the User PATH. You could try defining your environment under your User variables, but this would be more of a workaround than a solution.
PATH=%PATH%;%JAVA_HOME%\bin;%JRE_HOME%\bin;%MAVEN_HOME%\bin
You can diagnose these access errors with Rapid Environment Editor, which will tell you if certain PATH locations are invalid or inaccessible to you.

Related

Maven set up required everytime i close the terminal

i'm very new to this world.. so forgive me for silly explanations.
I've installed maven and all the setting is done. Also i created a maven.sh
Content:
# Apache Maven Environment Variables
# MAVEN_HOME for Maven 1 - M2_HOME for Maven 2
export JAVA_HOME=/usr/lib/jvm/java-11
export M2_HOME=/opt/apache-maven
export MAVEN_HOME=/opt/apache-maven
export PATH=${M2_HOME}/bin:${PATH}
At this point everything is working as expected, but every time i close the terminal it seems to forget some settings..
I have to open the terminal and execute the following commands to make it work again:
~$ cd /etc/profile.d
~$ source maven.sh
I don't know if it is just the way to use maven or i'm missing something, but it's kind of annoying writting the same commands every single time i want to execute maven.. so i would appreciate if you can explain me a way to automate it.
Some extra information:
OS : Ubuntu 20.0.4
JDK : 11
Not first time creating JAVA_HOME variable
After executing those commands above, it shows the correct JAVA_HOME, but it's forgotten after closing the terminal and shows the wrong JAVA_HOME again
Let me tell you guys, this is my first question on stackoverflow, so i will understand if you want to correct me about my manners and my bad english (it's not my mother tongue, i have to get used to it)
Thank you in advance!
I can think of a couple of ways you could resolve this problem given your situation, which is not maven-specific but rather terminal-specific --
Add a reference to your maven.sh script to your profile so that it runs when you start a terminal session. This can typically be accomplished by creating (or adding to) the .bash_profile file in your home directory. You could either add the contents of your maven.sh script to that file, or add source /etc/profile.d/maven.sh to it. From that point forward when you start a terminal session, the script gets run automatically and your variables are set correctly. See https://joshstaiger.org/archives/2005/07/bash_profile_vs.html or the bash man page for some more details about the login shell
If you've already done the first step and it didn't work, consider checking to see if those environment variables are being set in another place (check ~/.bashrc, ~/.bash_profile, and anywhere your particular shell distribution / OS checks for startup scripts
Lastly, I recommend using SDKMan! to manage maven installs without these headaches -- but your mileage may vary. It handles keeping track of the environment variables, java version, &c and allows multiple Java/Maven versions to be installed and managed. https://sdkman.io
Sources:
https://joshstaiger.org/archives/2005/07/bash_profile_vs.html
https://linux.die.net/man/1/bash
https://sdkman.io
You can add these properties to individual user settings file. This file will be available in home directory
vi $HOME/.bash_profile
So everytime, you login to terminal, all these settings will be executed.
I solved the problem by doing a logout and login in Ubuntu

Installing/running apache tomcat [duplicate]

This question already has answers here:
Tomcat is not running even though JAVA_HOME path is correct
(18 answers)
Closed 5 years ago.
New guy here! I need to install Apache Tomcat (among other things such as Java JDK and Eclipse) for a class. After downloading Java JDK (jdk1.8.0_152), I downloaded the Apache zip file (version 8.5.24) and transfered it to "Program Files". I then created the system variable "JAVA_HOME" (JAVA_HOME : "C:\Program Files\Java\jdk1.8.0_152"). When I tried to run the startup.bat in the command-line interface, it didn't worked and referred to the CATALINA_HOME variable not being defined. I then created the CATALINA_HOME variable (CATALINA_HOME : "C:\Program Files\apache-tomcat-8.5.24"). After that, when I try to run the startup.bat (I used this line : "C:\Program Files\apache-tomcat-8.5.24\bin\startup.bat"), I get Files\apache-tomcat-8.5.24"" was unexpected. That where I am at the moment... I looked into the forum and I am wondering if I am missing something in the Path variable. I also looked into this question (Tomcat is not running even though JAVA_HOME path is correct), but it didn't solved my problem.
Thanks!
Update
In my opinion, the other question was not exactly the same as mine (even though they are very similar) and the solution for me was also different. Running the startup.bat in the command line center was not working. Creating shortcuts solved my solution. Thank you all!
Seems like the space in "Program Files" messes up everything. Try adding the path surrounded with quotes. If that doesnt work you could move Tomcat directory to another place (which path does not contain spaces)
The problem solution at first sight should fix above answer. But there are other ways to fix it too.
You can also put the %CATALINA_HOME%/bin; in PATH variable. Than you can run $startup.bat command from terminal/console directly without giving any full path. In this case you will have to restart the terminal (command prompt) window.
Another handy feature is to create shortcut of startup.bat file in Desktop (may be) and just run it.

Ant is unable to find a javac compiler

I am trying to build some binaries of an application. When i am trying to make the build, I am getting this:
BUILD FAILED
/home/.../ant-build.xml:84: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "/usr/lib/jvm/java-8-openjdk-amd64/jre"
The application requires java 7, and i have it installed but i had it along java 8. The build requires for tools.jar which is located in java 7 only, therefore after several attempts i uninstalled java 8. However, when I am trying make again, i get the same error, even though i don't have java8 installed at all!
I set the JAVA_HOME properly:
$ echo $JAVA_HOME
/usr/lib/jvm/java-7-openjdk-amd64/
I doubt i need the path but i set that one up just in case as well :
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-7-openjdk-amd64/bin
I'm running out of ideas here :P any help would be appreciated.
Also something maybe important, I had to add the repo manually to get java-7 otherwise it wasnt able to locate the package. Thats when i got double jdk-s.
I guess you are calling the JAVAC command from any other source/tool like Jenkins/Bamboo/Teamcity. Make sure you have set the environment variable of that tool. usually it lies in the manage tool option.
I was facing same issue while using Jenkins.If you don't set up an environment variable in tool from which you are making a call it take your
"/usr/lib/jvm/java-8-openjdk-amd64/jre" so go and set the the env variable JAVA_HOME of you tools. attaching screen shot of Jenkins issue. Go to Manage Jenkins -->configure system --> environment variables and set you java_home path.
Cheers
I just encountered the same situation.
That is because JAVA_HOME is not correctly set in sudo environment.
I added export JAVA_HOME=/path/to in /root/.bashrc, and eventually it was built right.
It seems that you are using javac of java8 with JAVA_HOME or CLASS_PATH pointing to java7.
You can use which java to check that.
export JAVA_HOME=/lib/jvm/java-7-openjdk-amd64
export export ${PATH}=${JAVA_HOME}:/bin:${PATH}`

Maven - "files was unexpected at this time"

I'm trying to install maven to my PC.(windows 7)
Following are the steps I have done.
1. Installed Java 1.8.0.11
2. Added a system variable JAVA_HOME = C:\Program Files\Java\jdk1.8.0_11
3. Appended it to the path - PATH=%JAVA_HOME%\bin;C:\Program Files\......;... etc
4. Typed "Java -version" in command line and got the java version details as usual.
5. Then I downloaded and extracted the Maven 3.3.3
6. Added the M2_HOME to system variable.M2_HOME=C:\Program Files\apache-maven-3.3.3\apache-maven-3.3.3
7. Added M2 Variable M2=%M2_HOME%\bin
8. Appended M2 to Path variable. PATH=%M2%;%JAVA_HOME%\bin;....;...etc
9. Typed mvn --version in command line.
Get the following error.
Files was unexpected at this time.
What is wrong here?
Please help me to get this resolved.
Thanks in advance!
**Note - I have not use quotes for any of the paths here. also I tried with 8 char syntax for folder names like this:
set java_home="c:\Progra~1\Java"
Non of these were resolved the issue. Please read the steps I have added and help me to get this resolved.**
Finally I was able to resolved the issue.
A quoted value in the user variables has caused to the "Files were unexpected at this time" error in maven.
I spent hours of time with changing Java_home and M2_home variables with different combinations but finally checked the user variable and noted the quotes there.
Home = "C:\Program Files (x86)\Git\bin"
Removed the quotes and change the git home variable as below and now all works fine. :)
Home = C:\Program Files (x86)\Git\bin
I had a similar issue Files\apache-maven-3.3.9""=="" was unexpected at this time. and when looking at "Environment Variables" inside "System Properties" there were no quotes (") inside of any variables, but before doing that I was following a tutorial and set those values via cmd: C:\Program Files\apache-maven-3.3.9\bin>set M2_HOME="C:\Program Files\apache-maven-3.3.9"
So, in order to fix it I just re-run the following in cmd:
C:\Program Files\apache-maven-3.3.9\bin>set M2_HOME=C:\Program Files\apache-maven-3.3.9 (removed " from cmd assignment) I hope this helps someone.
Try adding
C:\Program Files\apache-maven-3.3.3\apache-maven-3.3.3\bin
to PATH variable
I was facing same issue in jenkins when I asked jenkins to install maven internally.
Notice double quotes below when jenkins was firing a build
'""C:\Program Files (x86)\Jenkins\tools\hudson.tasks.Maven_MavenInstallation\maven\bin\mvn.cmd"' -f ./Voyager/pom.xml clean package....
To resolve this I downloaded maven and manually set the path in jenkins and it was resolved.

Problems with maven installation

Hi I'm trying to install MAVEN, to my computer using this tutorial, I've set my enviroment variable MAVEN_HOME to point to my maven directory, and I put value of path_to_maven/bin inside another enviroment variable named Path and I get this error message:
C:\>mvn -version
'mvn' is not recognized as an in
operable program or batch file.
I've tried also to use PATH instead of Path but that doesn't solve it, what else can I do? I'm using windows 7..
Go to path_to_maven/bin and type mvn -version. If that works then it's a PATH problem.
In MS-DOS's prompt type set PATH=path_to_maven/bin;%PATH%
You may need to restart your computer for the changes to PATH to take effect.
I had a similar problem while configuring maven.
I've installed Maven 2 on my computer and I had problems when invoking mvn --version from cmd.
I've set the M2_HOME and M2_REPO environment variables and I have added to the system variable PATH the path_to_maven/bin.
In order to be able to invoke mvn from cmd I had to add still another environment variable named PATH with value path_to_maven/bin.
I hope this will help anyone caught in this issue.
If it helps someone:
Try to add the entire directory path in the PATH variable instead of using the referrals like %M2%.
Close the Command Prompt and then re-open it again.
Hit the command mvn -version. It should work if the environment/system variables are set properly.

Categories

Resources