这是我的Maven结构:
project
---src
----main
----java
----App.java
----resources
----config.properties
这是读取 config.properties 的代码:
private static final URL propFile = ClassLoader.getSystemResource("config.properties");
public App() throws IOException {
props.load(new FileInputStream(propFile.getFile()));
}
public static void main(String[] args) {
try {
App app = new App();
//Something interesting happens here
} catch (IOException e) {
e.printStackTrace();
}
}
当我跑步时java -jar MyApp-1.0.jar
,我收到FileNotFoundException
:
java.io.FileNotFoundException: file:/home/dragon/JavaProjects/MyApp/target/MyApp-1.0.jar!/config.properties (没有这样的文件或目录)
它有什么问题?