Changing the Java parameters
MsMohexon opened this issue ยท 7 comments
I am currently attempting to host a nomicraft server, and everything is going fine. However, the server attempts to use java 1.17 and not java 1.8. In the launch bat I see the Java Parameters tab, but quite frankly, I have no idea what ot put there to make the server use java 1.8.
Why not use like this:
"C:\Program Files\Java\jre1.8.0_351\bin\java.exe" %LAUNCHPARAMS%
Should I put that behind "SET JAVA PARAMETERS"? Apologies for all my questions, Im not too techsavy
Should I put that behind "SET JAVA PARAMETERS"? Apologies for all my questions, Im not too techsavy
No. "C:\Program Files\Java\jre1.8.0_351\bin\java.exe" - should be path to your java version. New java change PATH on update, and old version need full path to executable file in .bat file.
Do not hardcode java path in the launch file. Different operating systems have different java installations, it's not limited to C:\Program Files\
.
What you want to do is set JAVA_HOME
parameter and use it in the script. By default JAVA_HOME
variable is set by java installers (you don't have to manually set it to some value most of the times) and is easily modifiable (if you need to have multiple java installations).
So the result script would have such callers:
...
:: line 22
"%JAVA_HOME%\bin\java.exe" -version
...
:: line 29
echo ^> "%JAVA_HOME%\bin\java.exe" %LAUNCHPARAMS%
...
:: line 31
"%JAVA_HOME%\bin\java.exe" %LAUNCHPARAMS%
...
(Rename the file to launch.bat
)
launch.bat.txt
I do the same commands as you do in your screenshots, but it does not save. If i do %JAVA_HOME%\bin\java -version before i close the command prompt, it works just like yours (after typing the first ocmmand with my java version ofc) but if i reopen cmd to check again, the parameter is gone. The .bat also cant find it
Nevermind! Its running!
Java installers set the system PATH
to include a new environment variable called JAVA_HOME
, which contains the full path to the newly installed Java executable.
When you use SET
in the command prompt, it makes a temporary local change to the environment variable for that command prompt only. Newly opened command prompts are populated with the original system-level environment variables, hence why it's appearing to revert.
Changing JAVA_HOME
for the scope of the launch script is functionally no different than the suggestion made by Zebtrix to just put the quoted full path to the executable in place of java
. You do however have to run the SET
command before running the launch script every time, which is rather annoying, and why we recommend just hard coding the path when Java 8 is not your system-wide Java installation. If they change where Java 8 is installed, only then do you have to change the launch script again.