Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting environment variable for Java on Unix OS

 
Shinaya Seth
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to set variables on Unix OS that can be read by jar file at runtine. I tried setting the variable in user's .bash_profile file in JAVA_OPTS attributes.

Like:

JAVA_OPTS="-Djava.awt.headless=true
-Dvariable1=file:/home/file.xml -Dvariable2=file:/home/file2.properties"

This does not work as expected when I execute the jar file on Unix. Is there any other way that I set the variable for jar in Unix?
On windows, I can set this up in Computer>>Properties>>Advanced>>Environment variables.
I could set up this variable for tomcat on Unix as well but for some reason jar file does not read the variables.

Thanks.
 
Winston Gutkowski
Bartender
Pie
Posts: 10109
56
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shinaya Seth wrote:This does not work as expected when I execute the jar file on Unix.

I have to admit I'm not familiar with JAVA_OPTS, but two possibilities:
1. did you include export JAVA_OPTS in the .bash_profile? Or alternatively, use
export JAVA_OPTS="-Djava.awt.headless=true -Dvariable1=file:/home/file.xml -Dvariable2=file:/home/file2.properties"

2. You may still need to execute something like java $JAVA_OPTS other-parameters classname

HIH

Winston
 
Shinaya Seth
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) Yes I am doing the export $JAVA_OPTS

2) for running java $JAVA_OPTS other-parameters classname...will have to mention the jar file name for classname?
 
Campbell Ritchie
Sheriff
Posts: 48404
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Winston Gutkowski
Bartender
Pie
Posts: 10109
56
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shinaya Seth wrote:for running java $JAVA_OPTS other-parameters classname...will have to mention the jar file name for classname?

Yes. All I meant was add $JAVA_OPTS after the 'java' of the command you would have run anyway.

Winston
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic