Showing posts with label jdk. Show all posts
Showing posts with label jdk. Show all posts

Friday, September 21, 2018

Setting a specific Java version to maven if you've multiple Java versions installed in the system

This is for the macOS:

By default, maven runs with the default JAVA_HOME configured in the system. If you want to set a different Java version temporarily for your maven - we need to change the JAVA_HOME in the mvn file. 

mvn shell file

#!/bin/bash
JAVA_HOME="${JAVA_HOME:-$(/usr/libexec/java_home)}" exec "/usr/local/Cellar/maven/3.5.2/libexec/bin/mvn" "$@"


Changed mvn shell file this to:

#!/bin/bash
JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home" exec "/usr/local/Cellar/maven/3.5.2/libexec/bin/mvn" "$@"

However, if you wish to set a particular java version to the project permanently - that needs to be configured in the pom.xml file

Refer here:                   


For example, to set for Java 1.8
<properties>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.source>1.8</maven.compiler.source>
 </properties>


Java 7:

<properties>
        <maven.compiler.target>1.7</maven.compiler.target>
        <maven.compiler.source>1.7</maven.compiler.source>
 </properties>


 But where can I find this mvn file in macOS?
$ which mvn
/usr/local/bin/mvn

$ cat mvn
#!/bin/bash
JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home" exec "/usr/local/Cellar/maven/3.5.2/libexec/bin/mvn" "$@"

As you can see - mvn file is located in /usr/local/Cellar/maven/3.5.2/libexec/bin/



Monday, October 12, 2015

How to find the product code for the installed MSI file in windows

Run below command from power shell to see.

PS C:\Users\Admin> get-wmiobject -class Win32_Product


IdentifyingNumber : {32A3A4F4-B792-11D6-A78A-00B0D0170400}
Name              : Java SE Development Kit 7 Update 40
Vendor            : Oracle
Version           : 1.7.0.400
Caption           : Java SE Development Kit 7 Update 40

IdentifyingNumber : {32A3A4F4-B792-11D6-A78A-00B0D0170760}
Name              : Java SE Development Kit 7 Update 76
Vendor            : Oracle
Version           : 1.7.0.760
Caption           : Java SE Development Kit 7 Update 76

IdentifyingNumber : {32A3A4F4-B792-11D6-A78A-00B0D0170800}
Name              : Java SE Development Kit 7 Update 80
Vendor            : Oracle
Version           : 1.7.0.800
Caption           : Java SE Development Kit 7 Update 80

IdentifyingNumber : {64A3A4F4-B792-11D6-A78A-00B0D0170400}
Name              : Java SE Development Kit 7 Update 40 (64-bit)
Vendor            : Oracle
Version           : 1.7.0.400
Caption           : Java SE Development Kit 7 Update 40 (64-bit)

IdentifyingNumber : {64A3A4F4-B792-11D6-A78A-00B0D0170800}
Name              : Java SE Development Kit 7 Update 80 (64-bit)
Vendor            : Oracle
Version           : 1.7.0.800
Caption           : Java SE Development Kit 7 Update 80 (64-bit)


IdentifyingNumber  number represents the product code.

Wednesday, October 8, 2014

Maximum heap size allocated on 32 bit JVM's

http://www.oracle.com/technetwork/java/hotspotfaq-138619.html#gc_heap_32bit

The maximum theoretical heap limit for the 32-bit JVM is 4G. Due to various additional constraints such as available swap, kernel address space usage, memory fragmentation, and VM overhead, in practice the limit can be much lower. On most modern 32-bit Windows systems the maximum heap size will range from 1.4G to 1.6G. On 32-bit Solaris kernels the address space is limited to 2G. On 64-bit operating systems running the 32-bit VM, the max heap size can be higher, approaching 4G on many Solaris systems.

In nutshell:
Theoretically : 4GB
Practically:  1.4 to 1.6GB


Monday, September 8, 2014

Unsupported major.minor version 51.0

java.lang.UnsupportedClassVersionError happens because of a higher JDK during compile time and lower JDK during runtime.

51.0 in "Unsupported major.minor version 51.0" represents that, .class file generated with JDK 1.7 and but you are trying with run with(runtime) with lower version of it.

Below are the version numbers and compatible JDK's.

J2SE 8 = 52,
J2SE 7 = 51,
J2SE 6.0 = 50,
J2SE 5.0 = 49,
JDK 1.4 = 48,
JDK 1.3 = 47,
JDK 1.2 = 46,
JDK 1.1 = 45


To resolve this issue, make use of same version during the compile time and run-time.

Example: You would have generatd jar file with jdk 1.7 and but you are trying to run that jar using JDK 1.6 eclipse, this leads to above error.



Monday, April 7, 2014

How to check Installed Java is a 32 bit or 64 bit version ?


If you have installed JDK, Java would have registered in the system environment variables.

Go to command prompt and type “java –version”

C:\Users\kh1205>java -version
 java version "1.6.0_30"
Java(TM) SE Runtime Environment (build 1.6.0_30-b12)
Java HotSpot(TM) 64-Bit Server VM (build 20.5-b03, mixed mode)

If it’s a 64 bit Java, you will be finding “64-Bit Server VM” in the above line.

If it’s a 32 bit java, you will be finding “Client VM” in the above line.

I have another JDK configured in my system, for which I wanted to check java version.
For example, other version of java is available in the location “C:\Program Files (x86)\Java\jdk1.6.0_31

C:\Program Files (x86)\Java\jdk1.6.0_31\bin>java -version
 java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b05)
Java HotSpot(TM) Client VM (build 20.6-b01, mixed mode, sharing)


“Client VM” in the last line tell you that,  JDK is a 32 bit version.