File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Setting environment variable for Java on Unix OS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Setting environment variable for Java on Unix OS" Watch "Setting environment variable for Java on Unix OS" New topic
Author

Setting environment variable for Java on Unix OS

Shinaya Seth
Greenhorn

Joined: Jan 06, 2012
Posts: 2
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

Joined: Mar 17, 2011
Posts: 8008
    
  22

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


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Shinaya Seth
Greenhorn

Joined: Jan 06, 2012
Posts: 2
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

Joined: Oct 13, 2005
Posts: 39393
    
  28
And welcome to the Ranch
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8008
    
  22

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting environment variable for Java on Unix OS