[英]Where to put properties file (in connection with maven assembly)
當我在eclipse中啟動我的應用程序時,在src/main/resources
文件夾中有一個屬性文件是沒有問題的。 然后,當我運行maven install
,該屬性文件將在maven程序集的幫助下放入config
文件夾中。 所以下面的問題:
在Eclipse中工作時,我只需使用以下命令即可訪問屬性文件:
File propsFile = new File( "src/main/resources/settings.properties" );
maven install
之后,我當然再也無法訪問該文件了。 但是,在我的Eclipse開發期間和maven install
之后,兩次都不需要文件訪問文件,哪種工作流程是最好的?
在maven install
之后,我的程序集結構如下所示:
application folder
|----bin
|----batch file to start my application
|----lib
|----my application jar
|----other dependencies jars
|----config
|----settings.properties
提前非常感謝:)
如果您是通過一個腳本文件,啟動應用程式,我建議你要加入到類路徑,其中的文件夾settings.properties
位於:
在Eclipse中,您根本不需要執行任何操作,因為src\\main\\resources
中的所有文件實際上都被復制到了target\\classes
輸出目錄中,該目錄實際上位於類路徑的標題處。
並且,在腳本文件中,您只需在執行類路徑的開頭添加<application>\\config
文件即可。
但是,然后您必須更改從程序讀取資源的方式:使用ClassLoader.getResourceAsStream
使用File
API進行替換:
InputStream input=getClass().getClassLoader().getResourceAsStream("settings.properties");
Properties properties=new Properties(input);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.