File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Absolute path in webApp attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Absolute path in webApp attribute" Watch "Absolute path in webApp attribute" New topic
Author

Absolute path in webApp attribute

Guy Yafe
Greenhorn

Joined: Sep 30, 2011
Posts: 18
Hi All,
Does anyone know how to set an absolute path to the webApp attribute in a Host?
Something like "c:\...."
I can't figure out how to do it. Tried with "/", tried with "\" and nothing worked.
I am using tomcat 7.0 on Windows XP platform.

Thanks
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16020
    
  20

Welcome to the JavaRanch, Guy!

I'm not quite sure what a "webApp attribute" is, although if you're referring to a resource in a WAR, absolute filesystem paths aren't a good idea. For one thing, unless the WAR has been exploded, the closest you could get would be the filesystem path of the WAR file itself. And for your own sake, don't even even THINK about writing data into a WAR, exploded or not!

In most cases, the best way to address resources in a WAR is to use their WAR pathname: for example, "/WEB-INF/classes/log4j.xml". Even in DOS/Windows filesystems, this path should be using forward slashes and not backslashes as path separators. It's usually safer in Java to use the forward-slash notation anyway. Backslashes can bite you.


Customer surveys are for companies who didn't pay proper attention to begin with.
Guy Yafe
Greenhorn

Joined: Sep 30, 2011
Posts: 18
Hi Tim, Thank you for the reply.
I need the absolute path for development purpose: I have local library on which I develop and write the code. Once it is ready I upload it to SVN and pack it to a WAR file.
Of course it is not a good idea to have the under development code under the Tomcat library so I want the local instance of Tomcat to have the option to load an application from an absolute path.

Anyway I found my two mistakes:
The first was posting this message with a typo I was suppose to write "appBase" instead of "webApp"
The second was using the wrong path to my application.

Guy
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16020
    
  20

Ah. Big difference.

You can put a path in the Context element that you use to deploy the webapp with. In the case of a test setup like what you've got, your best best is to create an "xxx.xml" file containing the Context element and copy it into TOMCAT_HOME/conf/Catalina/localhost.

Please note that the context name in the Context XML element will be ignored if you do this, and the actual URL that the app is deployed under would be "xxx" (http://localhost:8080/xxx), so name that file appropriately!

And, yes, for the Context appBase, you SHOULD supply an absolute path. Relative paths are OK, but not as foolproof. So that would give you something like this:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Absolute path in webApp attribute