Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在模块化项目中获得再保险_Java_Maven_Maven 3 - Fatal编程技术网

Java 在模块化项目中获得再保险

Java 在模块化项目中获得再保险,java,maven,maven-3,Java,Maven,Maven 3,我正在从事一个maven模块化项目,其结构如下所示: |-- parent |-- model --pom.xml |-- services --pom.xml |-- web-app --pom.xml 不,在我的服务模块中,我在src/main/resources中有一些资源。但当我试图得到它们时: String fileName = getClass().getResource("/myFile.txt").getPath(); map.p

我正在从事一个maven模块化项目,其结构如下所示:

|-- parent
    |-- model
    --pom.xml
    |-- services
    --pom.xml
    |-- web-app
    --pom.xml
不,在我的服务模块中,我在src/main/resources中有一些资源。但当我试图得到它们时:

String fileName = getClass().getResource("/myFile.txt").getPath();
map.put("myReport",JasperCompileManager.compileReport(fileName));
文件名具有以下值

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

当我尝试使用它时,我得到:

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
我还看到其他帖子没有解决,比如有人说不可能从不同的模块获得资源

这是真的吗?
如何修复它?

看起来它工作正常,但您不能使用文件访问不透明路径。张贴你想做的事情。首先,我要告诉你,你的路已经走了!在jar文件名中。是不是搞错了?@Boristeider我更新了我的问题,在那里你可以看到我正在试图编写一份我用jasper report制作的报告。我经常使用getResourceAsStream,工作正常,然后我想了解为什么getResorce/myFile.getPath尝试访问.jar,而不是像getResourceAsStream这样的类路径,因为我在这里假设,JasperCompileManager.compileReport采用文件路径。您拥有的不是文件路径,而是不透明的路径。该文件位于.jar中,因此无法像普通文件一样打开。类加载器是专门为从JAR(即类)加载文件而设计的。您可以使用该流在jar外部创建一个副本,这样就可以了。