我有以下代码从资源中读取文件:
randomFirstName = rReader.generate(
new FileReader(classLoader.getResource("NamesFem.txt").getFile()));
当我从IDEA运行它时,它工作正常。
我需要使用maven将项目放入可执行jar。那是我的pom.xml
程序集插件配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>com.myPackage.CreateXlsFile</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
当我尝试运行打包的jar时,出现以下异常:Exception in thread "main" java.io.FileNotFoundException: file:/Users/myUser/MyProject/target/my-project-1.0-SNAPSHOT-jar-with-dependencies.jar!/NamesFem.txt (No such file or directory)
当我手动解压缩jar时,所有文件都在jar的根目录中:
怎么了?