safarisoul
safarisoul

Reputation: 246

Where does tomcat store txt files used by web applications

I have tomcat installed at "C:\Program Files\apache-tomcat-7.0.27"
I have eclipse installed at "C:\Program Files\eclipse"
And I have the workspace located at "C:\workspace"

I'm using "Java perspective", created a "Java Project" with the default output folder as "helloWorld/web/WEB-INF/classes". The structure of the project goes like this:

-helloWorld
---src
-----servlets
-------hello.java
-------world.java
---web
-----WEB-INF
-------jsp
---------hello.jsp
---------world.jsp
-------lib
-------web.xml
---helloWorld.xml
---record.txt

doPost() in hello.java generate a random number, and write it to a text file "record.txt".
doPost() in world.java open the text file "record.txt" and read a number.

The system is working, but what I originally put in the record.txt file in eclipse project never get changed, and I'm sure that what world.java read from the file is exactly what hello.java generated.
I checked "C:\Program Files\apache-tomcat-7.0.27\work\Catalina\localhost\helloWorld", and only jsp files are there.
I then tried restart tomcat and reload and even undelopy and deploy again, but the previous generated number is still there. I didn't try restart computer.

My question is where is the record.txt file? It is definitely not the one in the eclipse project.

Upvotes: 0

Views: 3815

Answers (3)

Martin Wilson
Martin Wilson

Reputation: 3386

If you use a relative file path in your Java code then it will not be relative to your webapp it will be relative to where the process running Tomcat was started. Therefore you might find your file in the Tomcat bin directory or somewhere similar.

If you want to create a file relative to your webapp then you need to obtain the path to your webapp, which you can do by calling getServletContext().getRealPath("") in your Servlet.

Upvotes: 1

HashimR
HashimR

Reputation: 3843

Check your webapps folder for a folder with the same name as your project.

C:\Program Files\apache-tomcat-7.0.27\webapps

Here you will find the exact folder structure and your record.txt file as well.

Hope this helps!

Upvotes: 0

thecodejack
thecodejack

Reputation: 13379

Eclipse deployed projects are run in temp folder. the path looks some thing like this... tmp0/conf/catalina/localhost/projectname.....context.xml of servers might help you in this..

i suggest u should go for an absolute path....i faced same problem while using eclipse...That time i had to even provide the link to the user...

Upvotes: 0

Related Questions