maven does not use 64 bit jvm - java

I am facing a weird issue in maven.
I am running java 1.8 in 64 bit windows .
When I run java -version I get the below message
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
I am running maven 3.3.9 on the above jdk.
When I run mvn -version I get the below message
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T19:41:4
7+03:00)
Maven home: D:\Users\57181\Projects\mvn\apache-maven-3.3.9-bin\apache-maven-3.3.
9
Java version: 1.8.0-ea, vendor: Oracle Corporation
Java home: D:\java\java8\java8\jdk1.8.0\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "dos"
However when I run mvn -d64 -version , I get below error
Error: This Java instance does not support a 64-bit JVM.
Please install the desired version.
I need to build a very large project using maven which needs 2 GB heap.
Though my machine has 8 GB RAM , I am not able to set the heap since Maven is running in 32 bit( In the task manager , the process shows as * 32 )
Has anybody faced this issue ?
Is there any configuration needed to run maven in 64 bit JVM ?

You are picking up the default JVM installed for web page plugins etc as it is in your PATH.
You can put the JDK directory first in your PATH environment variable which most likely is the simplest.
You may also choose to set the environment variable JAVA_HOME to point to the JDK you want to use, either as part of your environment or by modifying the mvn script.

Related

Reconcile java versions between maven and java

When I'm calling mvn --version I get the following :
Apache Maven 3.8.2 (ea98e05a04480131370aa0c110b8c54cf726c06f)
Maven home: /usr/local/Cellar/maven/3.8.2/libexec
Java version: 16.0.2, vendor: Homebrew, runtime: /usr/local/Cellar/openjdk/16.0.2/libexec/openjdk.jdk/Contents/Home
Default locale: en_US, platform encoding: US-ASCII
OS name: "mac os x", version: "11.4", arch: "x86_64", family: "mac"
So I take the version 16 is used
But when I'm calling java -version :
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment AdoptOpenJDK-11.0.11+9 (build 11.0.11+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK-11.0.11+9 (build 11.0.11+9, mixed mode)
Here I have java11.
I found out that the mvn command (found using which mvn) is actually a bash script in which the JAVA_HOME variable is defined, so I do get how I'm landing into /usr/local/Cellar/openjdk/16.0.2/libexec/openjdk.jdk/Contents/Home when running maven.
But what is extremely confusing is the behaviour of java -version. java refers to an executable /usr/bin/java that is just lying there. And if I set the JAVA_HOME :
JAVA_HOME=/usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home
Then java -version returns :
openjdk version "16.0.2" 2021-07-20
OpenJDK Runtime Environment Homebrew (build 16.0.2+0)
OpenJDK 64-Bit Server VM Homebrew (build 16.0.2+0, mixed mode, sharing)
So it looks like the /usr/bin/java executable reads this variable and calls the corresponding "real" java exec...
But then, my paramount question is : when the JAVA_HOME variable isn't defined, how the heck is this /usr/bin/java executable figuring where is the openjdk in version 11 ?
The short answer is on macos /usr/bin/java is the same executable as /usr/libexec/java_home. See the manual page for java_home(1) which references a "default order."

Maven on WSL2 can't see JAVA_HOME

I have JDK 11 and Maven 3.8.1 installed on my Windows 10 machine. Took care that install paths don't have spaces.
Made the value of JAVA_HOME visible inside the Ubuntu shell following the advice here. Then I restarted the Ubuntu shell.
Here are the outputs from inside an Ubuntu shell on Windows Terminal:
user#computer:/path$ java -version
openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.10+9)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.10+9, mixed mode)
user#computer:/path$ env | grep JAVA
JAVA_HOME=/mnt/c/AdoptOpenJDK/jdk-11-hotspot
user#computer:/path$ mvn -v
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
So although the value of JAVA_HOME is visible inside the Ubuntu shell, somehow mvn can't see it. How do I fix this?
Maven run from cmd gives this output:
C:\path>mvn -v
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: C:\Maven\bin\..
Java version: 11.0.10, vendor: AdoptOpenJDK, runtime: C:\AdoptOpenJDK\jdk-11-hotspot
Default locale: en_IN, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
Versions:
Windows 10 version 2004 (OS Build 19041.1110)
Java 11.0.10
Maven 3.8.1
WSL2
Ubuntu 20.04.2 LTS (via WSL2)
I gave up and simply installed JDK 11 & Maven 3.8.1 inside WSL2 using SDKMAN.
Not an ideal solution, but didn't feel like spending more time on this issue.
I don't disagree with your solution to use the Linux versions of Java and Maven inside WSL, but I do think I see why your example in the original question was failing.
The problem appears to be that you are using the Windows versions of Java/Maven, BUT your JAVA_HOME from inside WSL is using the "Linux form" of the path (/mnt/c/AdoptOpenJDK/jdk-11-hotspot).
Maven is complaining, because since it is running under Windows, it doesn't understand that path. It needs to see C:\AdoptOpenJDK\jdk-11-hotspot.
I believe this is because the answer you linked to said to use setx WSLENV "JAVA_HOME/p". The /p is forcing the translation from the Windows path to the WSL/Linux mapping, which you don't want in this case.
Also, be sure to restart the Terminal from which you launch WSL so that it can pick up the new environment variables.

mvn -version on command line showing different version of Java

I played around with jenv today, to setup Java 1.8 as global version and 1.7 for one project locally. Since then mvn command in the global locations is showing java version 12 -
SandeepanNath:current sandeepan.nath$ mvn -version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T22:11:47+05:30)
Maven home: /Users/sandeepan.nath/.sdkman/candidates/maven/current
Java version: 12.0.1, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home
Default locale: en_GB, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.3", arch: "x86_64", family: "mac"
Whereas Java version is showing as expected -
SandeepanNath:.ssh sandeepan.nath$ java -version
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
I tried uninstalling and installing maven via sdkman again, on Mac. Although it did not download it fresh. I am still getting the same error.
How do I fix this?
probably your answer might already be here: https://stackoverflow.com/a/7033062/4424668
I guess, you have set up a JAVA_HOME environment variable at some point, which points to a Java 12-Installation.
What might actually be the solution to your specific problem (Jenv + Maven) is written here: https://stackoverflow.com/a/37466252/4424668
You might need to enable the maven Plugin for Jenv by calling jenv enable-plugin maven. Afterwards, Maven should consider the version activated by Jenv.
Edit:
Since you actually use SDKMAN für managing maven candidates, you might consider using SDKMAN for Java Candidates as well. Anyhow, maybe the maven plugin does not actually fix your SDKMAN maven candidates. An even easier solution may be to enable the export-plugin instead, which actually sets the Environment Variable directly. Have a look about that on the Github-Page of Jenv: https://github.com/jenv/jenv

Environment variables returning blank even though Maven build is happening fine

I'm using Maven as a build tool for Scala code. I'm able to build the Scala objects fine using maven. However when I echo $M2_HOME ,$M2,$JAVA_HOME, everything is returning blank. While this is a sign that these environment variables are not set properly, they are not causing any issues, which to me sounded a bit surprising. Can you please let me know what I'm missing here. I'm running Ubuntu 15.04 and included the below output if needed.
~$java -version
openjdk version "1.8.0_45-internal"
OpenJDK Runtime Environment (build 1.8.0_45-internal-b14)
OpenJDK 64-Bit Server VM (build 25.45-b02, mixed mode)
~$mvn -version
Apache Maven 3.0.5
Maven home: /usr/share/maven
Java version: 1.8.0_45-internal, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.19.0-58-generic", arch: "amd64",family: "unix"
This is the first time I'm using Java, Maven and Scala so kindly excuse my ignorance.

Why am I getting the error "Obtained an unexpected kind of VM install" in Mulesoft's Anyponit Studio (Eclipse)?

Why does everything around Java need to be so ____ complicated? I am trying to run applications - that run on other people's machines - and getting the error:
Obtained an unexpected kind of VM install: null
Has anyone seen anything like this?
Anypoint Studio is a product provided by Mulesoft and based on Eclipse.
Mac OS X Yosemite
$ java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
$ mvn -version
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T07:57:37-04:00)
Maven home: /Users/jkalis/Maven/apache-maven-3.3.3
Java version: 1.7.0_79, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.10.3", arch: "x86_64", family: "mac"
You need to reference the version of the JRE that you want to use in the project properties.
Here are the steps to add it to your project.
Select the Project
Choose the Properties
Choose 'Java Build Path'
Click Libraries on the Dialog
Choose 'Add Library...'
Select 'JRE System Library'
Click Next
Choose the JRE System Library to use.
Click Finish

Categories

Resources