I have a JAR which accepts environment variable options. When I run the main class manually by setting run configuration, I provide environment variable as : KERBOROS_KEYTAB_LOC="location of the keytab file"
Now I need to set these options while running the JAR. How I can set that? I tried below option but it is not working.
java -DKERBOROS_KEYTAB_LOC="location of the keytab file" -jar jarfile.jar
On linux, execute
$ export KERBOROS_KEYTAB_LOC="location of the keytab file"
On windows
C:\>SomeDir>set KERBOROS_KEYTAB_LOC="location of the keytab file"
then run the jar as always
For Windows
.bat file
@echo off
setlocal enabledelayedexpansion
:: Load environment variables from .env file
for /f "delims=" %%i in (Variables.env) do (
set "%%i"
)
:: Run your jar
java -jar YourJarFileName.jar
:: Pause the script when exit occurs and wait for a key press
echo Press any key to exit...
pause >nul
endlocal
Variables.env to your name.env file where you have defined your env variablesYourJarFileName.jar.bat file.Note: Keep all these files, 3 of them in the same directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With