閱讀了關於該主題的大約50個不同的主題後,我無法使用任何解決方案。從JAR Maven項目中訪問屬性文件
我想要做的是在jar中訪問我的config.properties文件。
我的項目是一個Maven項目和架構如下:
- 我的項目
- 的src/main/java的
- 對myApp
- MyClass.java
- 對myApp
- 的src/main /資源
- icon.jpg
- config.properties
- 的src/main/java的
所以,當我嘗試從Eclipse中訪問其工作原理與完美的此代碼:
InputStream configFile = MyClass.class.getResourceAsStream("config.properties"); Followed by more code here to retrieve properties...(that works)
但是,當我將項目導出到可運行JAR時,它不再工作。罐子裏面,文件如下:
- File.jar
- MyApp的
- files.class這裏
- 等...
- META-INF
- 資源
- icon.jpg
- config.properties
- MyApp的
安置自己的'pom.xml'文件 – freedev
裏面的''部分你你的build jar文件中有真正的'resources'文件夾嗎?如果是,我假設你的配置/目錄佈局或你的pom配置是錯誤的... –
khmarbaise
這是我的pom.xml ' 4.0.0 modelVersion> MYAPP MYAPP 0.0.1-SNAPSHOT MYAPP \t http:// localhost:9000 ' –
retArdos