[英]Add resource file to artifact in Intellij Idea
我正在創建一個插件以反映並由主應用程序調用。 這個插件使用xml文件,我想使其成為嵌入式資源。 我將插件構建為工件(JAR)。 我的動作:
1)將xml文件放入配置為'source root'
目錄'trunk / res 'source root'
;
2)對目錄“ trunk / res”所在的模塊執行'make module'
操作;
3)進入插件,我通過文件路徑dom = db.parse("trunk//res//resource.xml");
訪問xml文件dom = db.parse("trunk//res//resource.xml");
但是,當我從主應用程序調用插件時,遇到關於系統的異常,找不到文件'MainApp/trunk/trunk/res/resource.xml'
。 我想我沒有正確提取資源,但是如何正確地提取資源呢?
嘗試致電:
System.out.println(getClass().getProtectionDomain().getCodeSource().getLocation());
看看您是否真的從jar呼叫。 接着
InputStream xmlFileStream = getClass().getClassloader().getResourceAsStream("res\\AIP_82.xml")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.