0

I have a maven project, working on Eclipse IDE. And I am trying to deploy it to the other linux machine having tomcat server, by export .war file from eclipse and put it to the other machine.

Here is the problem, when I execute(?) .war file by tomcat server, it automatically unzipped this file and make a project directory, however my resources in /src/main/resources spreads over var/lib/tomcat7/webapps/{project-root}/WEB-INF/classes and my original code to load some files doesn't work anymore

Here is the example.

String currentDir = System.getProperty("user.dir");
File mappingdir = new File(currentDir + "/src/main/resources/mapping");
File f = new File(mappingdir + "/a.csv");   

Result

HTTP Status 500 - java.io.FileNotFoundException:  
/var/lib/tomcat7/src/main/resources/mapping/a.csv (No such file or directory)

Because, this .csv file does not exists anymore. Its location is /var/lib/tomcat7/webapps/{project-root}/WEB-INF/classes/mapping/a.csv

How should I change the directory while developing java standalone code - if I consider deploy it to the web server?


My question is very much related to this question. Read file from /src/main/resources/

Community
  • 1
  • 1
SUNDONG
  • 2,501
  • 5
  • 21
  • 37
  • See http://stackoverflow.com/questions/19916845/cant-access-to-files-in-resources-directory-with-maven-with-eclipse-ide and http://stackoverflow.com/questions/10171122/resource-from-src-main-resources-not-found-after-building-with-maven – Jozef Chocholacek Jan 13 '16 at 08:12

1 Answers1

0

In java application all source files placed in /WEB-INF/classes folder. To read files from resources you shoul use

BufferedReader reader = new BufferedReader(
                new InputStreamReader(getClass().getClassLoader().getResourceAsStream("mapping/a.csv")));

it will work with standalone java applications too.

aios
  • 231
  • 2
  • 10