Win a copy of Fixing your Scrum this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Setting environment variable for Java on Unix OS

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 73725
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Oh, sure, you could do that. Or you could eat some pie. While reading this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic