Friday, April 29, 2011

Where is the "work" directory located for a Tomcat instance running in Eclipse?

In Eclipse you can configure numerous servers to run inside the IDE, including Tomcat. Depending on your Tomcat configuration, at some point in the life cycle of a webapp your JSP files will get compiled into servlets. These new servlet .class files are stored in the %TOMCAT_HOME%/work directory along with the .java intermediate file created from the JSP. This .java file is very helpful when your JSPs throw exceptions and cite a line number corresponding to the .java and not the .jsp

Update: On my environment (Windows), it is located here:

C:/Documents and Settings/%USER%/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/work

Perhaps to answer more completely somebody could post the location for *nix environments.

From stackoverflow
  • I assume it would be the same location relative to your workspace.

  • You can change it by setting scratchDir parameter in web.xml configuration of your server (in Servers project, not in your application web.xml!).

  • You will find it in

    projectworkspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0

    This is the default place where Eclipse 3.4 publishes the project. However, this can be changed by changing the settings in your 'Server' view.

  • The easiest way is most likely to ask a compiled JSP page about the source of the code.

    From http://www.exampledepot.com/egs/java.lang/ClassOrigin.html:

    // Get the location of this class
    Class cls = this.getClass();
    ProtectionDomain pDomain = cls.getProtectionDomain();
    CodeSource cSource = pDomain.getCodeSource();
    URL loc = cSource.getLocation();  // file:/c:/almanac14/examples/
    

    Hopefully this helps. What is it you want to do?

    Peter Štibraný : Great tip (if it works ;-))!
    Thorbjørn Ravn Andersen : I haven't tried it with JSP pages, but it works fine with plain classes in Tomcat. Also note that some JEE containers know how to work with unexploded web archives. The URL would then probably start with jar: - there is no guarantee that the URL is to a file resource.
  • Go to "Servers" window -> double click on your tomcat instance -> clik "Open launch configuration" -> go to "Arguments" tab.

    Look for variable definition like this:

    -Dcatalina.base="/Users/dirtyaffairs/Documents/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0"
    

0 comments:

Post a Comment