3

I am confused about how the current working directory is set in different Eclipse projects.

I have 2 Java applications I am running in Eclipse. One is a regular Java project, the other a J2EE servlet (Dynamic Web Project). At the top of each application I have this code:

    File currentDirectory = new File(new File(".").getAbsolutePath());
    System.out.println(currentDirectory.getAbsolutePath());
    System.out.println(currentDirectory.getCanonicalPath());
    System.out.println(System.getProperty("user.dir"));

Java project output:

C:\svn-source\Executor\.
C:\svn-source\Executor
C:\svn-source\Executor

J2EE project output:

C:\java\eclipse-jee-indigo-SR2-win32\eclipse\.
C:\java\eclipse-jee-indigo-SR2-win32\eclipse
C:\java\eclipse-jee-indigo-SR2-win32\eclipse

Why in the case of the Web project do I get the Eclipse root installation folder when the project I created is in a completely different place? Am I using the right classes for getting the current working directory? If so, could somebody please explain how the CWD is determined in each case (Java project vs the Web project).

Thanks.

driftwood
  • 2,051
  • 4
  • 21
  • 28
  • The ee project should inherit the cwd from the ee server since it runs in its context. And maybe eclipse doesn't start that in a new process but in it's own so your code inherits the cwd from the eclipse instance? Simple Java projects get their own environment. – zapl Oct 15 '15 at 19:00
  • By EE server you mean the web server the project is configured for? I configured the EE project to run on Apache Tomcat 6. The cwd wouldn't be something like "C:\Program Files (x86)\Apache Software Foundation\Tomcat 6.0"? – driftwood Oct 15 '15 at 19:30
  • You've a [XY-problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). The X is answered in the duplicate. – BalusC Oct 15 '15 at 21:36
  • would you mind giving a link to the answer please so I can see what my question is a duplicate of?? – driftwood Oct 16 '15 at 16:03
  • In case you haven't seen it at the top of your question; http://stackoverflow.com/questions/2308188/getresourceasstream-vs-fileinputstream – zapl Oct 16 '15 at 23:02
  • yep missed it completely. thanks. – driftwood Nov 01 '15 at 17:39

0 Answers0