File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes path problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "path problem" Watch "path problem" New topic

path problem

Prasath Premkumar
Ranch Hand

Joined: Nov 13, 2008
Posts: 43


I'v really stuck with an issue. I have done a web program using struts framework. I have a plugin class there for which i have to pass a configuration file as parameter. That file is in webapps/Myapp/WEB-INF/ directory. So i mentioned relative path as ../webapps/Myapp/WEB-INF/conf.xml. it works fine if i download tomcat zip file & extract it & use. Bt if i download a .exe file (eg: Apache-tomcat-5.5.15.exe) & run it to install & use it, struts doesnt get that path.

I'm really stuck with this prob. i need a way to specify path which works for both tomcat installations.

Please help me to solve this prob.

I thought to check where a file creates if i create a file from my program. When the is used i found the created test file is in bin directory of tomcat. That means tomcat defaultly points to bin directory, so the path to the config file ../webapps/Myapp/WEB-INF/conf.xml. works fine.
When i used tomcat.exe & installed tomcat in my machine & run the program,i found that the test file i created in my code level was in windows/system32/ directory. so in this case tomcat doesnt defaultly points to the bin directory i guess.

hope this helps to give me a good answer.
Thanks in advance.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2904

Why are you giving "webapps/Myapp/WEB-INF/ ", a path from webapps !! As the path is always configured from your current web application context, (here it is Myapp), and A good practice is not to rely on the current working directory. Always specify the full path to the file.
File f = new File("Myapp/WEB-INF/conf.xml");

or like that, think of path from "myapp" and not from webapps, that will help..

[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Prasath Premkumar
Ranch Hand

Joined: Nov 13, 2008
Posts: 43

Thanks for the reply.

Let me explain the problem again.

Inside WEB-INF directory i have classes,lib,struts-config.xml & conf.xml. i have to specify a plugin class & its parameter (conf.xml) in struts-config.xml file. That plugin class is in a jar which is in lib folder.

I created a test file from the class which gets pluged in, to see where the file gets created, so i can see where tomcat defaulty gets from. The test file was created in tomcat's bin directory.
so from there i gave the relative path to the file i needed to give as the argument. The lines i added in struts config is shown below.

<plug-in className="com.rcfi.qxlink.fixadapter.server.util. TFEInit">
<set-property property="configFile" value="../webapps/fixadaptorwebui-0.0.1/WEB-INF/conf.xml"/>

This works perfectly when i download file,extract it, & useit.
Bt the path problem occurs when v use tomcat.exe file to install tomcat & use it.

i dont knw y.

So for this case, i again created a test file, so i can see from where the path should start. Bt for this case (installed tomcat with tomcat.exe) the test file gets created in windows/system32 folder.
So no way to give a relative path from there.

Please help me to specify a relative path to the argument file (conf.xml) which should be given to the plugin class.

I have mentioned the folder structure & struts-config.xml lines in this post. hope this helps to give me a good reply.

Thanks in advance.
Joe Ess

Joined: Oct 29, 2001
Posts: 9189

Move your conf.xml to WEB-INF/classes and locate it with Class.getResource(String name) or open it with Class.getResourceAsStream(String name) . This is the preferred way to locate resources as it uses the classloader instead of depending on vendor-specific paths.
Smartly load your properties

[How To Ask Questions On JavaRanch]
I agree. Here's the link:
subject: path problem
jQuery in Action, 3rd edition