简体   繁体   English

将资源文件添加到Intellij Idea中的工件

[英]Add resource file to artifact in Intellij Idea

I'm creating a plugin to de reflected and call by main application. 我正在创建一个插件以反映并由主应用程序调用。 This plugin uses xml file and I want to make it embedded resource. 这个插件使用xml文件,我想使其成为嵌入式资源。 I build plugin as artifact (JAR). 我将插件构建为工件(JAR)。 My actions: 我的动作:

1) Put xml file to directory 'trunk/res' configured as 'source root' ; 1)将xml文件放入配置为'source root'目录'trunk / res 'source root'

2) Performed 'make module' action for the module in which directory 'trunk/res' is; 2)对目录“ trunk / res”所在的模块执行'make module'操作;

3) Into the plugin I access xml file through file path dom = db.parse("trunk//res//resource.xml"); 3)进入插件,我通过文件路径dom = db.parse("trunk//res//resource.xml");访问xml文件dom = db.parse("trunk//res//resource.xml");

But when I call plugin from the main application I get this exception about system cannot find the file 'MainApp/trunk/trunk/res/resource.xml' . 但是,当我从主应用程序调用插件时,遇到关于系统的异常,找不到文件'MainApp/trunk/trunk/res/resource.xml' I guess I don't extract resource properly, but how to do it correctly? 我想我没有正确提取资源,但是如何正确地提取资源呢?

Try to call: 尝试致电:

System.out.println(getClass().getProtectionDomain().getCodeSource().getLocation());

And see if you're really calling from jar. 看看您是否真的从jar呼叫。 And then 接着

InputStream xmlFileStream = getClass().getClassloader().getResourceAsStream("res\\AIP_82.xml")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM