Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

get the environment var in the servlet  RSS feed

 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello
in my servlet,there is following code block:
File f=new File("%JAVA_HOME%\\test.txt");
f.createNewFile();
the "JAVA_HOME" is the environment variable of my windows.after i deploy it to jboss,it threw exception.that tell me can't find the path.
then i modify it as:
File f=new File("%JBOSS_HOME%\\test.txt");
f.createNewFile();
the "JBOSS_HOME" is definde in its "run.bat " file.
the code still don't work.
who can tell me :
1 how can i use the environment variable of os or app server?
2 how and where can i set up a envrionment variable as the base dir ?
thank you.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's no supported way to get the value of environment variables in Java. You'd be better off setting up a context-level init param in your web.xml for these types of config variables.
 
zb cong
Ranch Hand
Posts: 416
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!