Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

relative path in servlet 1

Status
Not open for further replies.

unl33t

Programmer
Jun 8, 2004
2
0
0
CA
I am not too familiar with tomcat and servlets and i am in charge of moving a tomcat application to a new server.

The current application runs under tomcat 4.03 (win2k) and i am trying to get it to run under tomcat 5.0 (win2k3)

The app is built in many small .class files that do one set of tasks (one is for db stuff, one for file access...)

The app works on the new server after i adjusted some configurations except it pops this error on a few pages: AccesIO:FindChem:java.io.FileNotFoundException: webapps\UsefulApp\out\chem.out (The system cannot find the path specified)

This happens in one of the class files that gets called to read files from webapps\UsefulApp\out

The line where to problem occurs is the following:
BufferedReader in = new BufferedReader(new FileReader("webapps\\UsefulApp\\out\\chem.out"));

It works if i replace that path with an absolute one but it works on the current server as is.

Adjusting tomcat configuration would be much preferred than recompiling the code here as i don't have all the files that were used to compile the app.

Any suggestions would be greatly appreciated as i have already spent much time on this issue. Yes i used google and read thru the apache tomcat docs but something is still escaping me.

Thanks
 
Tomcat 4 and Tomcat 5 differ on how they interpret ".".

In tomct 4, if you started the server on the "TOMCAT_HOME/bin" directory, if you did :

File f = new File(".");

then it would take the base dir as "TOMCAT_HOME/bin".

But in Tomcat 5, it would take the base dir as "TOMCAT_HOME".

So, if you have relative paths, they will be screwed when moving from 4-->5.


If you have a JSP or Servlet, you can work out the filesystem directoy using something like :
Code:
ServletContext sc = getServletConfig().getServletContext();
String path = sc.getRealPath("/");
 
Thanks a lot for the answer!

I am starting it as a service, and when i write to a file directly without any path it ends up in c:\windows\system32

I'll search on how to change the directory where a service starts. Any tips on that ?

I tried so many things i had forgotten about this.

Thanks for the code snippet but this is something i can't include in the app as i can't compile the servlet because i lack some files. The file access is happenning in another class file which is just a regular java class file.

 
No ideas how to change the service start dir. All I really suggest is to forget the service, and run it off a batch file , "cd'ing" to a directory (either tomcat_home or tomcat_home/bin) that makes your paths work properly. Either that or edit the code recompile . You can tell Win32 to fire a batch file on startup, but it will mean having a console window running ....

Good luck !
 
To change Tomcat start directory under window service, you need modify/add the following to your the window registry.


[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\<TOMCAT_SERVICE_NAME>\Parameters]
"Current Directory"="<START_UP_DIR>"

where
<TOMCAT_SERVICE_NAME> is the name appears in window service
<START_UP_DIR> is the directory you want Tomcat to start up in.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top