8

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
1
  • 2
    FYI, -D sets a Java system property, not an environment variable. These are different and separate mechanisms that can be used for roughly similar purposes. May 15, 2019 at 21:29

3 Answers 3

11

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

2

Depends on what value you would like to pass as part of environment variable.

If its just key=valuepair where value is not location path, then you just use -Doption , just like how you do VM Args and run.

I had to pass EPAAS_ENV=e1 in environment variable and used below cmd

Java -DEPAAS_ENV=e1 -D<VM ARGS1> -D<VM ARGS2> -D<VM ARGS3> -jar <jarFile.jar>

enter image description here

-2

In general, You can pass the enviroment variable like below while running a jar file.

example:

java -Djava.security.auth.login.config="/path/kafkalogin.config" -jar myApplication.jar

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.