0

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
Laura
  • 5,088
  • 3
  • 26
  • 37
Shwetali
  • 11
  • 2
  • 3
  • 1
    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. – dave_thompson_085 May 15 '19 at 21:29

2 Answers2

2

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

admlz635
  • 729
  • 7
  • 13
-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

Shenoy
  • 737
  • 3
  • 11
  • 28
  • 1
    using `-Dkey...`, is not for setting environment variables, but would set a java system property. See https://stackoverflow.com/questions/7054972/java-system-properties-and-environment-variables – admlz635 Jun 25 '20 at 16:26