简体   繁体   中英

How to launch a 32-bit java process from a 64-bit java process without hardcoding paths

I have a 64-bit java application and I would like to run a particular jar application in 32-bit mode. For testing, I have done this in a disposable class:

public class Invoke32bit {

    public static void main(String[] args)
    {
        try {
            Runtime.getRuntime().exec("\"C:\\Program Files (x86)\\Java\\jre7\\bin\\java.exe\" -jar C:\\dev\\test.jar");
        } catch (Exception e)
        {
            e.printStackTrace();
        }
    }
}

And it works...but how can I avoid hardcoding the java path? The machines that will be using this application will have both 64-bit and 32-bit JRE's installed (this application is used internally and we don't have to worry about anyone else using it)

One approach I've thought of is to provide a config file to allow users to enter the path to 64-bit and 32-bit java, but if there was a way to automate this that would be better.

You have the java System property java.home , but that points to only one installation and there is never any guarantee that there is a 32 bit JRE also present.

You could use the other available system properties to 'crawl' for other, 32-bit JRE installations, but of course that's not fool proof (what if someone decides to install their JRE in some odd place where you are not looking for it?

Alternatively, you could package a 32 bit JRE with your software and invoke that. The obvious drawback is the size of your distribution.

On system properties: http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html

Related topic: possible to force a 64-bit JVM to use 32-bit mode via the argument "-d32"? (it's not possible)

Read Oracle Official Tutorial about Configuration Utilities .

You can use Properties, Command-Line Arguments and/or Environment Variables to mention a few methods.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM