'How to start 64-bit Java application from 32-bit C++ application?

I'm using a simple C++ program to run an executable .jar file in Windows 7 64 bit. I expected this to execute 64 bit java, but it doesn't, it executes the 32 bit version.

I'm using the following code:

const char* javaw_path     = "javaw.exe";
const std::string memory   = "-Xmx" + user_configured_memory();
const char* jar            = "-jar";
const char* jar_file       = "\"HelloWorld.jar\"";
const std::string cli_args =  get_cli_args(argc, argv);

const char* args[] = {javaw_path, memory.c_str(),
       jar, jar_file, cli_args.c_str(), static_cast<char*>(NULL)};    

const int ret = execvp(javaw_path, args);

When the java application starts up it logs the machine architecture as 'x86' rather than 'amd64' as expected. I get this information by checking:

System.getProperty("os.arch")

When I run the same command from the command prompt things work as I expected - The java app logs 'amd64'.

How can I change my start up program to launch 64 bit java?



Solution 1:[1]

We can have combinations of OS, JDK and Eclipse bit--ness, for instance a 64-bit JDK with a 32-bit Eclipse on a 64-bit OS, or 32-bit OS, 32-bit JDK, 32-bit Eclipse, 64-bit OS, 32-bit JDK, 32-bit Eclipse, or 64-bit OS, 64-bit JDK, 64-bit Eclipse. As someone mentioned above, if your programming in C++ on 32-bit, cannot be compiled, it has to be done on 64-bit and of course another 64-bit app to run the exe.

Solution 2:[2]

If your C++ program is 32-bit, you can't do it. You must compile the C++ app as 64-bit and then you can call another 64-bit app from the executable.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Silviu Ciuta
Solution 2 Piotr Surma