I tried to make the title as descriptive as possible, but im basically trying to locate javaw.exe
because when I launch my JAR cmd only finds java.exe
but the prompt window is ugly and I don't want it there.
What works:
java -jar myJar.jar
What I'm trying to do
javaw -jar myJar.jar
What also works:
JAVAWPATH\javaw.exe -jar myJar.jar
I'm trying to make the program adapt to any computer automatically, since I don't know if javaw will always be in the same location.
So I have managed to locate a bunch of "javaw.exe" files using
WHERE /R c:\ *javaw.exe
I want to select one of the returned paths and set some kind of string variable with which I can then: elevate MYstringPATHtoJAVAW -jar myJar.jar
.
I've written a batch script which locates the java instalation folder through the registry:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@ECHO OFF
:: Export java settings from registry to a temporary file
START /W REGEDIT /E %Temp%.\java.reg "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft"
:: Find java location
FOR /F "tokens=1* delims==" %%A IN ('TYPE %Temp%.\java.reg ^| FIND "INSTALLDIR"') DO SET JAVA_HOME=%%B
SET JAVA_HOME=%JAVA_HOME:"=%
SET JAVA_HOME=%JAVA_HOME:\\=\%
SET JAVA_HOME
:: Get java version
FOR /F "tokens=1* delims==" %%A IN ('TYPE %Temp%.\java.reg ^| FIND "CurrentVersion"') DO SET JAVA_VERSION=%%B
SET JAVA_VERSION=%JAVA_VERSION:"=%
SET JAVA_VERSION
SET JAVA_VERSION=%JAVA_VERSION:.=%
SET JAVA_VERSION=%JAVA_VERSION:_=%
SET /A JAVA_VERSION=%JAVA_VERSION%
:: Delete temp file
@DEL %Temp%.\java.reg /S /Q > NUL 2>&1
:: Check java version compatibility
IF %JAVA_VERSION% LSS 16020 (
ECHO.
ECHO YOU NEED AT LEAST JAVA WITH VERSION 1.6.0_20 -- this is just an example echo.
GOTO :EOF
)
PAUSE
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
I've used this as a base.But it might not work properly if the installed java is a 64bit (yes, I must update this script...) , but it can be updated easy.Hope this will help you.