0

I have a java web service (.war file) that I deploy to a few different environments, namely Apache Tomcat 7.0.x and JBoss EAP 6.1.x. When I open a File object (File file = new File("./test.file");), the absolute path is different based on which application server I am using. I output the absolute path by calling file.getAbsolutePath().

For Tomcat, it appears to look for test.file in the Tomcat/bin directory, but for my instance of JBoss EAP, it looks for /test.file, i.e. system root.

Is there some configuration parameter or environment variable for either of these two application servers that dictates the working directory?

fiveclubs
  • 2,392
  • 2
  • 18
  • 28

2 Answers2

0

Tomcat uses CATALINA_HOME,
I don't know much about JBoss,
but I think that uses EAP_HOME and JBOSS_HOME

  • I think you're right about CATALINA_HOME, perhaps with a 'bin/' appended to it, based on what I'm seeing. – fiveclubs Feb 09 '16 at 18:03
0

The working directory in a webapp is relative to the servlet context.

And its correct. The getAbsolutePath method returns to you the corresponding path for the path give into

see here https://docs.oracle.com/javase/7/docs/api/java/io/File.html#getAbsolutePath()

or here for example

http://www.mkyong.com/java/how-to-get-the-filepath-of-a-file-in-java/

But, if do you want the path absolute to the current webapp then you can try this one:

What does servletcontext.getRealPath("/") mean and when should I use it

Community
  • 1
  • 1
J. Beltran
  • 61
  • 4