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"
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 was wondering why mvn shows that Java version: 9.0.1, while my current java command is 1.8.0_151? Thanks.
$ mvn --version
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T03:58:13-04:00)
Maven home: /home/t/program_files/programming/Maven/apache-maven-3.5.2
Java version: 9.0.1, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-9-oracle
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.13.0-26-generic", arch: "amd64", family: "unix"
$ java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
Note that I have installed both java 8 and java 9:
$ update-alternatives --config javac
There are 2 choices for the alternative javac (providing /usr/bin/javac).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-9-oracle/bin/javac 1091 auto mode
* 1 /usr/lib/jvm/java-8-oracle/bin/javac 1081 manual mode
2 /usr/lib/jvm/java-9-oracle/bin/javac 1091 manual mode
$ update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-9-oracle/bin/java 1091 auto mode
* 1 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 manual mode
2 /usr/lib/jvm/java-9-oracle/bin/java 1091 manual mode
and
$ which java
/usr/bin/java
$ readlink -f /usr/bin/java
/usr/lib/jvm/java-8-oracle/jre/bin/java
and the only part in $PATH is
/usr/lib/jvm/java-8-oracle/bin:
/usr/lib/jvm/java-8-oracle/db/bin:
/usr/lib/jvm/java-8-oracle/jre/bin
and
$ echo $JAVA_HOME
/usr/lib/jvm/java-9-oracle/
A solution which I don't quite understand:
$ export JAVA_HOME=/usr/lib/jvm/java-8-oracle/
$ mvn --version
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T03:58:13-04:00)
Maven home: /home/t/program_files/programming/Maven/apache-maven-3.5.2
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.13.0-26-generic", arch: "amd64", family: "unix"
Does mvn rely only on JAVA_HOME, while java doesn't?
The mvn command is actually a shell script, and that script makes the decisions about which version of Java is used for the JVM that runs maven.
The thing that determines which JVM is uses are the $JAVA_HOME and / or $JAVACMD environment variables:
Normally, $JAVA_HOME from your environment is used to find the java command. Typically `$JAVA_HOME/bin/java" is used.
If $JVMCMD is set, that overrides $JAVA_HOME
If you have an /etc/mavenrc file, or a ~/.mavenrc, then these are "sourced" first. So they may override the settings of $JAVA_HOME, etc from your environment.
If $JAVA_HOME or $JAVACMD are not set explicitly, then the "mvn" script tries to find the "best" Java installation by platform specific means. You may or may not end up with the version selected via "alternatives" and/or the current setting of $PATH.
Also note the you can set Java versions in your POM file. These affect the source and target versions for the code you build, but they do NOT affect the version of the JVM that runs your builds. (So if you were to select Java 9 in your POM and try build with a Maven on Java 8 JVM, then Maven would give an error.)
Does mvn rely only on $JAVA_HOME, while java doesn't?
Basically, yes with a couple of nuances:
mvn has fall-back logic for the case where $JAVA_HOME is not set.
java actually depends on how you have configured your $PATH. If you put $JAVA_HOME/bin (or similar) ahead of /usr/bin in your $PATH, then the shell won't see /usr/bin/java and your "alternatives" setting will be ineffective. (The alternatives mechanism for Java works by installing symlinks to commands as /usr/bin/java, /usr/bin/javac and so on.)
Does update-alternatives --config javac affect $JAVA_HOME?
It doesn't. The alternatives system works by updating symbolic links.
Bottom line:
If you want to ensure that mvn uses a specific Java version (without interfering with anything else), export the appropriate JAVA_HOME variable in your mavenrc file.
If you want to really understand what is going on with mvn, read the script!
Why does mvn show that Java version: 9.0.1, while my current java command is 1.8.0_151?
The short answer is because you have two different versions of Java installed. When you type java from the command line, it uses one version. mvn finds the other version.
You can see which java executable is used by typing
which java
The output from mvn shows that it is using the JDK installed at /usr/lib/jvm/java-9-oracle.
The command-line uses the PATH environment variable to search for executable files when you type a command. You can see the value of it by typing
echo $PATH
If both directories for Java 8 and Java 9 appear in the PATH, then the shell will use the first one found. You can tweak the order of PATH, but it is probably best just to remove the one that you don't want to use by default.
Does mvn rely only on JAVA_HOME, while java doesn't?
Yes, maven use $JAVA_HOMEenvironment variable to find java installation while terminal always refer $PATHto find executable files in the system.
PATH is an environment variable on Unix-like operating systems, DOS, OS/2, and Microsoft Windows, specifying a set of directories where executable programs are located
So if you need to change the java version which is referred by maven, you have to change the $JAVA_HOME variable.
Or else take a look at How to change maven Java version in pom.xml
does update-alternatives --config javac not affect JAVA_HOME?
No. See this
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.
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
Oracle released Java JDK 7 on April 26 for Mac OS X. I followed the install instructions and when I do java -version in a terminal window I get:
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)
However when I do mvn -version in the terminal window I get:
Apache Maven 3.0.2 (r1056850; 2011-01-08 18:58:10-0600)
Java version: 1.6.0_31, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.7.3", arch: "x86_64", family: "mac"
How can I get Maven to use the Java JDK 1.7.0_04?
Thanks for the help.
Finally found the answer here:
http://www.adam-bien.com/roller/abien/entry/java_se_development_kit_7
You should use JAVA_HOME=$(/usr/libexec/java_home) instead on a Mac and then set the current jdk via "Java Preferences.app".
Set JAVA_HOME in ~/.profile
The problem is that the symbolic link "CurrentJDK" inside the versions of JavaVm.framework points to the old jdk, so when i used the following commands to set the CurrentJDK to the latest one (1.7.0_45) it works
cd /System/Library/Frameworks/JavaVM.framework/Versions
sudo rm CurrentJDK
sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents CurrentJDK
reference: http://java.dzone.com/articles/installing-jdk-7-mac-os-x
To find the path from Java Preferences, try
/usr/libexec/java_home -X
My Java7 entry looks like this:
<dict>
<key>JVMArch</key>
<string>x86_64</string>
<key>JVMBundleID</key>
<string>com.oracle.java.7u04.jdk</string>
<key>JVMEnabled</key>
<true/>
<key>JVMHomePath</key>
<string>/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home</string>
<key>JVMIsBuiltIn</key>
<false/>
<key>JVMName</key>
<string>Java SE 7</string>
<key>JVMPlatformVersion</key>
<string>1.7</string>
<key>JVMVendor</key>
<string>Oracle Corporation</string>
<key>JVMVersion</key>
<string>1.7.0_04</string>
</dict>
You need to change the JAVA_HOME environment variable to the new JDK 1.7 location.
Look at this question for possible locations where JAVA_HOME might be defined. In a terminal, type which java to find the path of your Java installation, and then update JAVA_HOME to point to that path (but exclude the trailing bin folder).
In case anyone is installing Maven on a 64-bit Mac running Mac OSX 'Mavericks' save yourself some time and some hair pulling trying to get Maven installed. I was trying to follow this (which failed because the location of the java_home has changed on Mavericks:
http://maven.apache.org/download.cgi
I was pulling my hair out until I found this website, which recommends you Install homebrew and follow the instructions on this page: http://techspunky.blogspot.in/2013/10/how-to-install-maven-on-mac-osx-109.html
once complete don't panic when $ maven -version doesn't work, instead use $mvn --version as maven.apache.org/download.cgi recommended.
It worked, but then I noticed the Java SDK Maven was using was Java version: 1.6.0_65, which is not the latest SDK I installed on the system.
Once I set the JAVA_HOME=/usr/libexec/java_home
It was using the correct SDK:
Maven home: /usr/local/Cellar/maven/3.1.1/libexec
Java version: 1.7.0_45, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9", arch: "x86_64", family: "mac"
Success!
but wait...
next time I opened the terminal and ran mvn -v it went back to java version 1.6. WTH!
its some sort of supposed bug from what I read use:
echo JAVA_HOME=/usr/libexec/java_home -v 1.7 | sudo tee -a /etc/mavenrc
and now:
Maven home: /usr/local/Cellar/maven/3.1.1/libexec
Java version: 1.7.0_45, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9", arch: "x86_64", family: "mac"
The reason Maven is still using Java 6 is that the /usr/bin/mvn script that launches it does not use the correct OS/X method for resolving the current Java version as specified in Java Preferences. See this Maven issue for details:
http://jira.codehaus.org/browse/MNG-4226
Voting it up might get it fixed; in the meantime, if you alter the /usr/bin/mvn script as shown in the comments & patch on that issue you will get the desired result.
Ok on my machine. Yes, the Oracle installer didn't exactly do its job, and it confused me to no end after 1.6 was still running.
java run time was updated
java -version
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
but the SDK HOME is actually a sim link still pointing to 1.6
/Library/Java/Home in finder GetInfo points to /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
in Terminal
./Home -> /System/Library/Frameworks/JavaVM.framework/Home
Go figure.
I found 1.7 here and I'm using that to build with: /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home
I think the problem lies partly with the java launch mechanism. I have been able to get Eclipse to run my code under Java7, but I think eclipse itself is still running under Java6. Also, I have a java program that was last compiled a year ago, and built using jarbundler-2.1.0.jar (with option jvmversion="1.6+"). When I double click the .app file it runs Java6, but when I double click the .jar file inside the .app it runs Java7.
Also, I do not use JAVA_HOME, but I still get the correct java version "1.7.0_04" shown in the question. JAVA_HOME seems to be a red herring. Maybe Maven needs it, but Eclipse doesn't seem to use it, and neither does launching jar files.
And after setting Java7 in the Java Preferences tool, it does not seem to affect launching .app java files. However it does make 'java -version' from the terminal work nicely. I tried unchecking everything but the Java7 option, and then Eclipse wouldn't run at all.
If your JAVA_HOME is located at the local user's bash, mvn will pick the system's current java version no matter what JAVA_HOME you've set.
Hence first run the command 'which mvn' and check which executable mvn you are using. After that edit that mvn file and change the JAVA_HOME variable to your prefered java home.