spring - Tomcat deployment file paths (for Java I/O process) -


I implemented a simple file I / O in my project for my project (then inside of war) Using the file) a .properties file contains the path () and now I need to do it in the server.

Earlier, when I included the files in the War file, I can access them in the Tomcat server using the path

  / Home / my_username / tomcat7 / webapps / my_project / web-nf / class /  

but now files are not inside the war file, The webapp is placed around the folder.

The structure of my Tomcat 7 folder is:

  tomcat7 | ---- & gt; Bin | ---- & gt; Conf | ---- & gt; Logs | ---- & gt; Resources * | ---- & gt; Temp | ---- & gt; Webapp | ---- \ ----> Springapp.war * | ---- & gt; Work  

where / resource is the folder that I need inside the war file I / O.

My .properties is in the file:

  dir.server = home / my_username / tomcat7 / resource // or dir.server = / Home / my_username / tomcat7 / resource  

but shows an error (from my catalina.out file):

  java .io.FileNotFoundException: / home / my_username /. Tomcat7 / resources / java.io.FileInputStream.open (native resident method) is java.io.FileInputStream on my_file.file (such a file or directory); Init & gt; (FileInputStream.java:120) at java.io.FileInputStream. & Lt; Init & gt; (FileInputStream.java:79) on weka.core.SerializationHelper.read (SerializationHelper.javaociety70)  

Is there a proper way to declare file paths or do I have to file I / O Implementation will change?

The reason for this is that you have a FileNotFoundException because your posted war < You should use this line of code in your program / code> on other systems or something that does not include that exact path.

  string tomcatpath = System.getProperty ("catalina.base")  

This will give you back path in that particular system in the template folder if the system is But if you have deployed war , there is a separate route for Tomcat, which will be returned, after that you can use the file in the properties resource folder by adding strings for the path

< Pre> string tomcatPath = System.getProperty ("catalina.base") .; String property filepath = tomcatpath + "/ resource";

You can use the code to use a particular file:

  string filePath = propertiesFilePath + "my_file.file";  

You should take a look:

Hope it helps .. :)


Comments