Error: Could not find or load main class $MAVEN_HOME - java

while running maven clean I am getting the following error :
Error: Could not find or load main class $MAVEN_HOME
while doing mvn -version I got :
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T22:11:4
7+05:30)
**Maven home: D:\mavenSecurity\apache-maven-3.3.9\bin\..**
Java version: 1.7.0_79, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_79\jre
Default locale: en_IN, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
I have set MAVEN_HOME = D:\mavenSecurity\apache-maven-3.3.9 in user variable in environment setting
Path in system variable in environment setting : D:\mavenSecurity\apache-maven-3.3.9\bin
Since I am getting other error previously so I have done the following also as mentioned in this post:
Eclipse error setting up Maven project for class exercise: Check $M2_HOME environment variable and mvn script match
-Dmaven.multiModuleProjectDirectory=$MAVEN_HOME
I have consulted other links but still I am getting the error while running MAVEN CLEAN in eclipse juno

This worked for me with the 3.3.9 version. The only difference is :
1) Add both M2_HOME and MAVEN_HOME variables in the Windows environment, and point it to your Maven folder (Note: I have added it to system variables)
2) Update PATH variable, append Maven bin folder – %M2_HOME%\bin, so that you can run the Maven’s command everywhere
Post output of mvn –version again if you face the issue. Also try running mvn clean from the command line and post the results.

configuring Maven on Eclipse. you have to tell eclipse where Maven has been installed so that it can use the Maven installation to build our projects.
Win 7 64 . Here is how i did my config.

Related

Error "the JAVA_HOME environment variable is not defined correctly" on running "mvn clean javadoc:jar package"

When I try to execute the command
mvn clean javadoc:jar package
it shows
the JAVA_HOME environment variable is not defined correctly. This environment variable is needed to run this program.
NB: JAVA_HOME should point to a JDK, not a JRE.
I checked out the already asked question Unable to find javadoc command - maven and the solution I tried above were taken from this solution only. I am new to Ubuntu. How can I fix this?
Whereas when I run echo $JAVA_HOME it prints:
/usr/lib/jvm/java-11-openjdk-amd64
I also tried setting the JAVA_HOME to:
/etc/launchd.conf/java-11-openjdk-amd64
/usr/libexec/java-11-openjdk-amd64
/usr/libexec/java-11-openjdk-amd64/
When I run mvn -v, it prints:
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 11.0.10, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "5.8.0-45-generic", arch: "amd64", family: "unix"
And when I run echo $JAVA_HOME it prints:
/usr/lib/jvm/java-11-openjdk-amd64
Hmm..., probably the file doesn’t exist for running javadoc. Does the file /usr/lib/jvm/java-11-openjdk-amd64/bin/javadoc exist?
Please try:
sudo apt install openjdk-11-jdk
I would remove the above listed packages with pattern openjdk-11-.* (see this question) and install Java like this.
On my Mac (big Sur) I was getting the same problem. After reading this article ; this command worked for my enviroment:
export JAVA_HOME=$(/usr/libexec/java_home)

Change JDK in IntelliJ seems not working

I'm on Windows, I've already set the Path to JDK 1.8 in Environment Variables.
Also in Project Structure, I've already changed to it. I have a Maven project.
On command line, if I use `mvn --version' I see
Apache Maven 3.0.4 (r1232337; 2012-01-17 15:44:56+0700)
Maven home: C:\apache-maven-3.0.4
Java version: 1.8.0_77, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_77\jre
Default locale: en_AU, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "dos"
However, in IntelliJ, if I hit the Run button, it always points to JDK 1.7, and an error is thrown (since my maven project requires java 8). How do I change that? Thanks
"C:\Program Files\Java\jdk1.7.0_09\bin\java" -Xms512m -Xmx1024m -Dclassworlds.conf=C:\apache-maven-3.0.4\bin\m2.conf -Dmaven.home=C:\apache-maven-3.0.4 -Didea.launcher.port=7534 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 11.1.5\bin" -Dfile.encoding=UTF-8 -classpath "C:\apache-maven-3.0.4\boot\plexus-classworlds-2.4.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 11.1.5\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher --no-plugin-registry --fail-fast --strict-checksums --update-snapshots -f C:\Users\Tung\server-pinbike\api-pinbike2\pom.xml install
Update
After following #BevyQ tip, I found that the JRE of Maven runner was pointing to Jre7, that's the reason.
See screenshot below, hope it helps someone.
Have you checked your modules settings?
In Project Structure, click Modules->"Your modules"->Dependencies to see what SDK you are using.
And you should check the Run configurations too.
I am able to repo your scenario by setting the Project SDK to 1.7 then set them module SDK to 1.8.
The version you got by using commend line, is the version that windows is using. It doesn't mean that version is applying to you project or your module in IntelliJ.
So, please double check if you set both project and module's SDK to 1.8.
Below are some screen shots of my repo.
I set module SDK to 1.8. And set Project SDK to 1.7
Mvn version is 1.8. But it will using 1.7 when I run the project

Installing maven problems

I have just installed Maven. I execute in a CMD console mvn -version, it works.
C:\>cd apache-maven-3.3.3
C:\apache-maven-3.3.3>mvn -version
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T13:57:3
7+02:00)
Maven home: C:\apache-maven-3.3.3
Java version: 1.8.0_25, vendor: Oracle Corporation
Java home: C:\Program Files (x86)\Java\jre1.8.0_25
Default locale: es_ES, platform encoding: Cp1252
OS name: "windows 8", version: "6.2", arch: "x86", family: "dos"
When I try to execute command c:\mvn -version I receive a list with the possible commands of java.
What can be the reason for that?
I believe that you have not set the PATH variable in your windows system.
Navigate to Advanced System Settings -> Environment Variables -> System Variables
Copy "C:{path_to_maven}\bin" and append it to your 'Path'
environment variable.
And Also it is recommended that you set the
M2_HOME
in the User Variables Section to "C:{path_to_maven}\" so that you do not run into troubles in the future
If you need more details, go to the official page of maven by clicking on this link.
Add M2_HOME variable in the Windows environment, and point it to your Maven folder. Update PATH variable, append Maven bin folder: %M2_HOME%\bin, so that you can run the Maven’s command everywhere.

How does maven know JAVA_HOME set as an environment variable inUbuntu

When I type mvn --version in ubuntu from the terminal(ubuntu),I get the below output.
Warning: JAVA_HOME environment variable is not set.
Apache Maven 3.0.5
Maven home: /usr/share/maven
Java version: 1.7.0_79, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-32-generic", arch: "amd64", family: "unix"
When I did not set any JAVA_HOME environment variable , how is maven getting the java home installed path.Is it trying to find this path from the /usr/bin/java command which is installed in my system and if so why is it taking the path till jre.
P.S : Also I could not find any java path in any maven config.
Thanks.
As showed in the CLIReportingUtils.java (the maven class that retrieves the Java Home), the value comes from the following call :
System.getProperty( "java.home", "<unknown java home>" )
The java.home is for the JRE unlike the JAVA_HOME which is for the JDK.
So Maven is displaying the JRE home.
I would say there is a difference between JAVA_HOME environment variable and the output Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre.
The latter is just the output of the installation directory see here.
So maven will run Java in background and java knows where its installed.
I think,I understand it now.In the maven script i.e (usr/share/maven/bin/mvn) they are trying to find the java installed using a variety of options.
So at one place they are doing the below
JAVACMD="`which java`"
And now in my system "which java" points to the below
java -> /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
Hope this is how its getting the java path.

Netbeans Maven project: JAVA_HOME is not defined correctly

I have a NetBeans Platform project build with Maven2. When I try to create a new platform module I get this strange error:
cd ~/src; JAVA_HOME=/usr/lib/jvm/jdk1.7.0/bin/java ~/netbeans-7.3/java/maven/bin/mvn -DarchetypeGroupId=org.codehaus.mojo.archetypes...
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/lib/jvm/jdk1.7.0/bin/java/bin/java
In ~/.bashrc I have definition of JAVA_HOME:
export JAVA_HOME="/usr/lib/jvm/jdk1.7.0"
export JDK_HOME="/usr/lib/jvm/jdk1.7.0"
There's no slash at the end, however maven appends /bin/java/bin/java to this path. I can build already existing module with Maven without problems, just when creating a new one it fails. Where does Maven get this JAVA_HOME?
EDIT:
maven settings:
$ mvn -version
Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200)
Java version: 1.7.0_17
Java home: /usr/lib/jvm/java-7-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "3.2.0-39-generic" arch: "amd64" Family: "unix"
You're redefining JAVA_HOME on the command line to point to /usr/lib/jvm/jdk1.7.0/bin/java, which is wrong:
cd ~/src; JAVA_HOME=/usr/lib/jvm/jdk1.7.0/bin/java ...
Remove the JAVA_HOME=/usr/lib/jvm/jdk1.7.0/bin/java from the command line:
cd ~/src; ~/netbeans-7.3/java/maven/bin/mvn -DarchetypeGroupId=org.codehaus.mojo.archetypes...
netbeans takes the JAVA_HOME from the definition of the Java Platform in the IDE (See Tools/Java Platforms)
unless you select a custom platform, IDE uses the default one which is the one the IDE is running on.
All platforms need to be defined in the Tools/Java Platforms dialog and validation checks are in place to select the right folder.
Maybe something changed in time for you and the definition there is not correct?
the problem was with incorrect definition of JAVA_HOME in ~/.bash_profile
NetBeans integration of maven prefers:
System.getenv("JAVA_HOME")
before:
System.getProperty("java.home")
for linux find the mvn executalble file under netbeans's java/maven/bin folder and add
from="/bin/bin/java"
to="/bin/java"
JAVACMD="${JAVACMD/$from/$to}"
before the lines
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly."
cheers

Categories

Resources