我正在使用 maven exec 插件来运行一个简单的 java 类。这个 java 类加载一个文本文件。按照 maven 的方式,我在里面有我的文本文件:
src/main/resources
编译后,资源最终位于:
target/classes
编译后的源代码。当我尝试运行时:
maven exec:java
我得到:
Caused by: java.io.FileNotFoundException: text.txt (The system cannot find the file specified)
如果我将 text.txt 放在 ${basedir} 中,这个错误就会消失,但是这是不对的,因为它不遵循 Maven 标准。有办法配置吗?
最佳答案
您应该将代码更改为 read it from classpath as a Resource
instead of reading it as File
, maven 从你的 ${basedir}
(你的 pom 所在的地方)执行 java
你的代码似乎试图在当前目录中查找,这就是它失败的原因
关于java - maven-exec-plugin 找不到资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19433641/