简体   繁体   中英

JDK 32bit and 64bit on JAVA_HOME simultaneously

I am using smartGIT in Windows 8.1 which uses 32Bit JDK (1.8), I needed to set JAVA_HOME to 32bit directory

but now Im using as well Android Studio which needs JDK 64bit (1.8 installed), and I need to set JAVA_HOME pointing to 64bit directory

is there a way to set them both on the same variable and depending if the software requires either JDK 32 or 64 can pick the appropriate framework???

I tried to set them simultaneously by separate them with a semi colon like this

JAVA_HOME

C:\Program Files\Java\jdk1.8.0_25\;C:\Program Files (x86)\Java\jdk1.8.0_25

but this just works with 32BIT version, 64BIT is still doesn't work

thanks for the support

This is not a direct answer to your question. But I think this will help you to solve the underline problem of running SmartGit on 64bit JVM.

Go to bin folder under SmartGit installation directory. There you can find the "smartgit64.exe" executable to launch SmartGit in 64bit mode.

I have it running smoothly in Win8.1 64bit with 64bit JDK.

There is no way to have a static JAVA_HOME that satisfies version or bitness specific subprocess that I know of.

You don't say what platform you are on, but generally environment variables exported such that subprocesses can use them are fixed, are used as a basis for further tweaks, or are completely redefined.

But, what you can do is try to tweak the environment that those processes are called from so they have their own custom environment. For example, you could have your own JAVA_ROOT set, andf then use that as a basis for creating JAVA_HOME along with a hard-coded or script/function fetched environment variable for a specific JRE to make the "real" JAVA_HOME for everything run from this subshell.

Alternatively, if you are on OS X, there is a utility that can be used to set and fetch system information for installed JREs. This can be used in scripts, etc. Other platforms have similar tools.

Also, look hard at your toolset. Make sure that JAVA_HOME is the only way to set the VM it uses -- often this is just one of the ways you can set this.

[EDIT]

I forgot about the -d32 trick mentioned in the comments. That would be nice solution if it works, and you can use the same versions of the VM for all invocations.

[EDIT]

Ok, since you are on Windows, you could try launching each Java app from its own environment. A .cmd or .bat file if that is the way you roll, or you could create a Windows shortcut that you tweak before invoking the specific app.

For example, if one has a Java main they want to run from the command line, it is easy to wrap the entire command line in a .bat file. eg:

set JAVA_HOME=C:\Some\Path\To\A\JRE
set APP_HOME=C:\Some\Path\To\A\Jar
set JAVA_OPTS="-Dfoo=bar"
%JAVA_HOME%\bin\java.exe %JAVA_OPTS% -jar %APP_HOME%\myApp.jar

Now, running this jarfile will use the specific Java executable you set, and also pass the new JAVA_HOME environment to the Java process that it starts. This overwrites any "default" JAVA_HOME you have set in your User or System environment.

Any other processes will not see this JAVA_HOME, and when the .bat file exits the new definition disappears.

Alternatively, if you always start your Java apps or Java tools by double-clicking them, you might be able to wrap those applications in a Windows shortcut -- even if you just prepend the executable with "set JAVA_HOME=..." I always forget how tweaky this is, though, so I'm hand-waving a bit!

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