Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

File is deleting when calling shutdown.bat

 
sal sathya
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI All,
In special situation i want a set of data that has to be store in a .ser file,means some values that has to store if tomcat is shutdown,and when tomcat restarted those values has to read from the file,so i use serialization of java and store the data at "tomcat_home\webapps\axis2\WEB-INF\classes"=='SaveValue.ser'.
In my program i used
static {
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
System.out
.println("---------------------Running Shutdown Hook-----------------------------");
writeObjects();
}
});
}
the writeObjects() will do the serialization as described here http://www.javabeginner.com/uncategorized/java-serialization .
if i click close button or press cntl-C while tomcat is running the SaveValue.ser will created and store in the location tomcat_home\webapps\axis2\WEB-INF\classes ,but when i click shutdown.bat the file is not creating .
what is the problem how can do serilization with tomcat restart in axis2 webservice.please help me
Thanks in advance
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18212
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should NEVER write files to anywhere inside a WAR. It's neither safe nor reliable. Always write them somewhere outside the WAR. The WAR should be treated as read-only, because in many cases it actually is read-only.

You're also not doing yourself any favours by using Windows-style pathnames. If you forget to escape the backslashes, you can get in all sorts of trouble. It's safer to use forward slashes when working in Java.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic