I try to set the visual code settings for .csvode settings.json for wsl to the path where the wsl resides with the home folder. But I keep getting error that it does not point to a jdk. I have tried pointing to the local installation on windows as well as the place where the jdk resides on the wsl. None of which is working.
$ mvn -version
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 11.0.8, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.4.0-18362-microsoft", arch: "amd64", family: "unix"
Tested and failed settings of the wsl settings:
{
"java.home": "C:\\Java\\java-11-openjdk-11.0.8.10"
}
and
{
"java.home": "/usr/lib/jvm/java-11-openjdk-amd64"
}
As well as variants where I add or remove slashes as well as bin folder.
Press Ctrl+Shift+P to open Command Platte and choose Java: Configure Java Runtime:
Turn to Java Tooling Runtime, JDK for Language Server will show all installed and eligible JDK for java extension, which is jdk11 or recent version. Choose the one that you've installed:
Then reload VS Code to make change effective.
Related
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.
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.
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 use Intellij Idea. Now I'm trying to set up new system and have came up with the next issue:
I've downloaded java, installed it, set JAVA_HOME(C:\Progra~2\Java\jdk1.7.0_51), added to PATH (C:\Progra~2\Java\jdk1.7.0_51\bin), checked from console java -version and %JAVA_HOME% - everything works fine (java version "1.7.0_51"Java(TM) SE Runtime Environment (build 1.7.0_51-b13) Java HotSpot(TM) Client VM (build 24.51-b03, mixed mode, sharing)).
I've downloaded maven, installed it, set M2_HOME(C:\Progra~2\Java\maven), added to PATH(C:\Progra~2\Java\maven\bin), checked from console mvn -version(Apache Maven 3.3.3 2015-04-22T14:57:37+03:00) Maven home: C:\Progra~2\Java\maven Java version: 1.7.0_51, vendor: Oracle Corporation Java home: C:\Progra~2\Java\jdk1.7.0_51\jre Default locale: ru_RU, platform encoding: Cp1251 OS name: "windows 7", version: "6.1", arch: "x86", family: "windows") and enter cd %M2_HOME% - it goes there normally.
But when I try to do mvn -clean or -install or any other action from Intellij, it says:
-Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.
Process finished with exit code 1
If you use the newest Maven 3.3.3 you have to take care of the new calling design. It changed from bat to cmd files. Your IDE probably isn't right now compatible to this new design. Try to take an older version of maven.
Maybe you have a look here too: `-Dmaven.multiModuleProjectDirectory not set` issue with Maven and IntelliJ
IntelliJ ships with a bundled Maven thus your settings and maven installation will not be picked up unless you explicitly specify Intellij to use your maven installation and not the bundled one.
You can verify it under: Maven Settings (use CTRL+SHIFT+A to find it if you can't locate it)
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.