Wrox Programmer Forums
|
Apache Tomcat General discussion of the Apache Tomcat servlet container. For discussions specific to the Professional Apache Tomcat book, please see the book discussion forum for that book.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Apache Tomcat section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 13th, 2009, 04:56 AM
Registered User
 
Join Date: Mar 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Question Path problem

Hi, 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. Note: I thought to check where a file creates if i create a file from my program. When the tomcat.zip 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.
 
Old March 24th, 2009, 12:03 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 373
Thanks: 0
Thanked 1 Time in 1 Post
Default

When you install tomcat using as a service [windows setup file installation] it runs from system32 directory. but when you extract the zip file and run the catalina.bat it starts from tomcat/bin where the bat file is available.

One solution can be to place this .xml file in tomcat/shared/classes directory so that its always available to you, but its available to all web applications! and the deployment script should handle placing it to the shared/classes directory.

Another solution could be to load the xml file content as streams using getClass().getClassLoader().getResourceAsStream() method. this getResourceAsStream() takes file name as parameter, and the path will the relative to the Class you are using to get the resource.
For example
Code:
Class Test {
 public void testMethod(Class class) {
   // if abc.txt is available in the same directory as Test.class
   // can give relative path here
   InputStream in = class.getClassLoader().getResourceAsStream("abc.txt");
 }
 public static void main(String[] args) {
   Test o = new Test();
   o.testMethod(Test.class);
 }
}

I've not compiled this code, just wrote it while replying, but thats a way to load resources.

Hope it helps :-)
__________________
- Rakesh
http://iam-rakesh.blogspot.com
 
Old March 24th, 2009, 12:39 AM
Registered User
 
Join Date: Mar 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot rakesh for the reply.

The getResourceAsStream() method doesnt work since that conf.xml file is out of the jar which the plugin class is located. The jaris in WEB-INF/lib & the conf file is in WEB-INF/ directory. I cant place it inside the jar since the user should be able to edit it.

I'l try the other option. (tomcat/shared/classes).

thanks again.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Path problem sureshp2p Apache Tomcat 1 September 4th, 2007 06:13 AM
Implementing the all-path shortest path problem bitwords XSLT 1 December 6th, 2006 11:37 AM
problem with x-path expression ashyabhi_hp XSLT 3 February 1st, 2006 05:07 AM
DB Path problem creative_eye Classic ASP Databases 1 March 7th, 2005 11:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.