1

I thought about using the following code, but is there any cleaner way?

Process theProcess = Runtime.getRuntime().exec("java -d64 -version");
BufferedReader errStream = new BufferedReader(new InputStreamReader(theProcess.getErrorStream()));
System.out.println(errStream.readLine());
Kara
  • 6,115
  • 16
  • 50
  • 57
rkatiyar
  • 290
  • 1
  • 2
  • 10

4 Answers4

1

If you are using Sun JVM, I think you can use the sun.arch.data.model system property (using the System.getproperty() to get this value.

Gangadhar
  • 1,893
  • 9
  • 9
1

You can use

String arch = System.getProperty("os.arch")
if (arch.equals("amd64") || arch.equals("x86_64")) {
    // Machine is 64-bit
}

To determine whether the machine itself is a 64-bit machine. Not sure about checking the VM itself, though.

Haldean Brown
  • 12,411
  • 5
  • 43
  • 58
1

Decided to post this as an answer:

public static boolean supports64Bit() {
    try {
        final Process process = Runtime.getRuntime().exec("java -d64 -version");
        try {
            return process.waitFor() == 0;
        } finally {
            process.getInputStream().close();
            process.getOutputStream().close();
            process.getErrorStream().close();
        }
    } catch (IOException e) {
        // log error here?!
        return false;
    }
}

Closing all streams associated with a process is good practice and prevents resource leaks.

Not tested.

whiskeysierra
  • 5,030
  • 1
  • 29
  • 40
0

The simplest way to do so, may be through Java WebStart and a local JNLP file. You then invoke "javaws foo.jnlp" with appropriate options.

You can have architecture dependent options and libraries.

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347