This appears to be a problem I do not see on linux or Windows machines. I have my environment setup with a JAVA_HOME derived from /usr/libexec/java_home. This is in my .bashrc file:
export JAVA_HOME=$(/usr/libexec/java_home -version 1.7)
which results in:
~/dev/Endeavor/endeavor-sdk$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home
However when I run Maven on my project, I get an error from the native2ascii plugin:
[ERROR] Failed to execute goal org.codehaus.mojo:native2ascii-maven-plugin:1.0-alpha-2-SNAPSHOT:native2ascii (default) on project dataAccessServices: Error starting Sun's native2ascii: -> [Help 1]
My investigation points to that I am using a JRE instead of a JDK. That's odd since I am clearly pointing to the JDK in my JAVA_HOME variable. However, here is the output of mvn -version:
~/dev/Endeavor/endeavor-sdk$ mvn -version
Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
Maven home: /usr/share/maven
Java version: 1.7.0_17, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.7.5", arch: "x86_64", family: "mac"
Notice the "Java home:" line indicates that the ${java.home} variable has been moved to the JRE instead of the JDK that the JAVA_HOME environment variable points to.
I have tried setting the JAVA_HOME in numerous places but I can't seem to find a way to get maven to use the JDK as the home and not the JRE.
UPDATE:
I found this that appears to indicate that this is expected behavior: Java_home in Maven
But that does not explain why the native2ascii plugin cannot find the JDK tool it needs.
I have removed the use of native2ascii since it was largely unnecessary. So, I am avoiding the problem at this point. However, if anyone has an idea as to why this behaves differently on different systems, please let me know.
Have you tried running mvm help:system that should print all environment variable values that are relevant to maven?
There has been lots of discussions on this matter and here Java_home in Maven you can find a real good answer.
In a nutshell: your configuration it's just right, it is just a matter of semantics. You can read further here: http://javahowto.blogspot.com/2006/05/javahome-vs-javahome.html
Related
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)
I am trying to build a maven project on centOS 8. I want maven to use Java version 15. When I run mvn package I get the following error:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile
(default-compile) on project systembrett-backend: Fatal error compiling: invalid target release: 15 -> [Help 1]
So I suspect that maven is using the wrong Java version, because when i do mvn package -X for debug logs it start with:
Apache Maven 3.5.4 (Red Hat 3.5.4-5)
Maven home: /usr/share/maven
Java version: 1.8.0_275, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.275.b01-1.el8_3.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-240.1.1.el8_3.x86_64", arch: "amd64", family: "unix"
so it looks like, maven is using Java version 1.8.
But mvn -version says:
Apache Maven 3.5.4 (Red Hat 3.5.4-5)
Maven home: /usr/share/maven
Java version: 15.0.2, vendor: AdoptOpenJDK, runtime: /opt/jdk-15.0.2+7
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-240.1.1.el8_3.x86_64", arch: "amd64", family: "unix"
JAVA_HOME is /opt/jdk-15.0.2+7 and PATH is /opt/jdk-15.0.2+7/bin:/home/username/.local/bin:/home/username/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin.
I thought maven is choosing the java version by checking JAVA_HOME, but apparently it is using an other version for the build. Does anyone know how to tell maven the correct version?
Thanks!
Following is a list of steps I use to troubleshoot this kind of issues:
Linux usually works with alternatives to ensure proper default Java environment is used. Similar to:
$ alternatives --config java
There are 2 programs which provide 'java'.
Selection Command
-----------------------------------------------
+ 1 java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.191-2.6.15.4.el7_5.x86_64/jre/bin/java)
* 2 java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-3.b13.el7_5.x86_64/jre/bin/java)
Try also for javac as it may not be configured the same way:
$ alternatives --config javac
For your maven instance, JAVA_HOME should be enough.
Your output of mvn -version testifies that you have configured it correctly. Remove your Java from your PATH to ensure JAVA_HOME and mvn will find the correct one.
The pom.xml can also configure the required compiler, similar to:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Another thing may be that you're not using the same ENV (different terminals may not have the same environment variables exported - I presume you being on CentOS, you already encountered this). You have to exit the terminal and get back in to allow the default variables to take effect.
You encounter this usually when different JRE vs JDK are used ( more: maven installation has runtime as JRE instead of JDK )
I had the same issue on RHEL 9.1. The solution was to look at /etc/java/maven.conf and set the correct JAVA_HOME here in this file.
Before I start, let me tell you that I've been Googling for about an hour or two now, so please don't respond to this question saying "Hey! You know that there's plenty of answers on Google?"
Now to the question: whenever I run mvn clean package, I get the this error No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?. I've checked my Java versions, and these are the outputs.
Java JRE
java -version returned java version "1.8.0_181"
Java JDK
javac -version returned javac 1.8.0_181
Maven version
mvn -version returned
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T20:33:14+02:00)
Maven home: C:\Program Files\Apache\maven
Java version: 1.8.0_181, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jre1.8.0_181
Default locale: nl_NL, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
From what I found on Google, there should be a line saying Java Home or something followed by the JDK version and it's path. As you can see, It's not appearing here. I've tried setting the JAVA_HOME variable multiple times, and I verified that it works, by executing echo %JAVA_HOME, which returned it's proper path.
Any help?
EDIT
Output of echo %JAVA_HOME%: C:\Program Files\Java\jdk1.8.0_181
System variables:
Do you have JDK_HOME, JAVA_HOME and MAVEN_HOME environment variables set?
As #Chris311 says in his comment echo %JAVA_HOME or set in Windows will show if the environment variables was set and set correctly.
set JAVA_HOME
And yes, JAVA_HOME should point to JDK, not a JRE. For example, for my Windows Machine, it is JAVA_HOME=C:\Program Files\Java\jdk1.8.0_181.
Update
As we figured out, it did not work in the git bash console, but it worked in the command line. I tested mvn clean package myself, it seemed to be working. However, some commands that work in cmd do not work in git bash, for example set java_home or cd to a path with \ (I needed to use /).
I had the same issue('mvn clean install' was working on the cmd, but not in the Git Bash) and it was resolved by removing the following from the path variable in Environment variables
"C:\Program Files (x86)\Common Files\Oracle\Java\javapath"
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.
I've spent quite some time trying to figure out what I'm doing wrong and hoping someone may be able to help.
My current setup is running Maven 3.3.3 (via homebrew) and Java 1.8. IntelliJ 13 is the IDE of choice.
Running mvn -version results in the following:
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-
22T12:57:37+01:00)
Maven home: /usr/local/Cellar/maven/3.3.3/libexec
Java version: 1.8.0_45, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.2", arch: "x86_64", family: "mac"
which I believe means everything is OK, but when I go to my IDE and try to run a Maven project I get this error:
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java -Dmaven.home=/usr/local/Cellar/maven/3.3.3/libexec -Dclassworlds.conf=/usr/local/Cellar/maven/3.3.3/libexec/bin/m2.conf -Didea.launcher.port=7539 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 13.app/bin" -Dfile.encoding=UTF-8 -classpath "/usr/local/Cellar/maven/3.3.3/libexec/boot/plexus-classworlds-2.5.2.jar:/Applications/IntelliJ IDEA 13.app/lib/idea_rt.jar" com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher -Didea.version=13.1.3
-Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.
Process finished with exit code 1
My M2_HOME var is set to /usr/local/Cellar/maven/3.3.3/libexec, the same directory where homebrew installed it, and this also matches the IDE settings.
One search lead me to believe it may be something to do with Maven version and the IDE but I'm not convinced. Can someone please shed some light on this please?
Just in case you have that error again go to Settings -> Maven -> Runner and add
-Dmaven.multiModuleProjectDirectory=$M2_HOME
to VM Options.
I had this wired issue while trying to build CAS Overlay Template using Maven. I could resolve it by adding the following environment variable:
MAVEN_OPTS = -Dmaven.multiModuleProjectDirectory
From the original question, the OP has solved their issue through this approach.
I upgraded to IDEA 14, imported settings, created a new Spring project and it worked out of the box.