How to detect 64-bit Java from the command line?

Is there a way to get Java internal properties, such as sun.arch.data.model, from the command line on Windows? I need a command to host a script package that detects the type of java architecture: 32-bit or 64-bit.

+5
source share
4 answers

If you are using Sun VM (and I would suggest that other virtual machines have similar information in their version information), you can check the "64-bit" line in the output of "java -version":

java -version 2>&1 | find "64-Bit" >nul:

if errorlevel 1 (
    echo 32-Bit 
) else (
    echo 64-Bit
)
+5
source

jarnbjo script is for windows. In a Unix shell, you can use the following script.

  #! / bin / sh

  BIT = `java -version 2> & 1`

  case "$BIT" in
    *64-Bit*)
    echo "64-Bit"
    ;;
    *)
    echo "32-Bit"
    ;;
  esac
+2

The following is the prescribed property dump program: linky

+1
source

If you install Groovy , you can use

groovy -e "System.properties.each{println it}"

for all properties, and

groovy -e "println System.properties['sun.arch.data.model']"

for specific properties.

Installing Groovy is as easy as extracting the zip and adding to the path.

+1
source

All Articles