Get reosurce in a modular project

*爱你&永不变心* 提交于 2019-12-11 18:57:07

问题


I'm working on a maven modular project that has a structure that look like at the following:

|-- parent
    |-- model
    --pom.xml
    |-- services
    --pom.xml
    |-- web-app
    --pom.xml

No in my service module I have some resources in src/main/resources. But when i try to get them:

String fileName = getClass().getResource("/myFile.txt").getPath();
map.put("myReport",JasperCompileManager.compileReport(fileName));

the file name has the following value

file:/home/myUser/apache-tomcat-8.0.3/webapps/myApp/WEB-INF/lib/services-0.0.1-SNAPSHOT.jar!/myFile.txt

and then when i try to use it i get :

Caused by: java.io.FileNotFoundException: file:/home/myUser/apache-tomcat-8.0.3/webapps/myApp/WEB-INF/lib/services-0.0.1-SNAPSHOT.jar!/myFile.txt

Also i saw others post (not resolved) like Get file in the resources folder in Java where somebody said the is not possible to get resource from different modules.

Is this true? How can I do to fix it?

来源:https://stackoverflow.com/questions/24104819/get-reosurce-in-a-modular-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!