I am trying to build a .war file with a with a custom .txt file added inside the project. which will be accesses at run time after the .war has been built and deployed.
For example:
My project in eclipse will look as such:
src
| |-Package1
| |-Config.class
| | Package2
| |-Controller.class
files
| |-text.txt
|
|-Pom.XML
I am trying to read in the text.txt file in which I can use to print out text in the controller class. This must be achieved after the .war.
Currently so far I have the following:
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>files</directory>
</resource>
</webResources>
Java Method:
@RequestMapping(value="/")
public ModelAndView test(HttpServletResponse response) throws IOException{
BufferedReader br = new BufferedReader(new FileReader("files/text.txt"));
String curr;
try {
while((curr = br.readLine()) != null) {
System.out.println(curr);
}
} catch (IOException e) {
e.printStackTrace();
}
return new ModelAndView("home");
}
Does anyone have an idea how this can be achieved? I must be able to get the abs path of it in the .war directory as I plan to use a cmdline to execute it.