简体   繁体   English

Maven配置:将文件放在类路径jar中作为参数

[英]Maven configuration: pass file inside a classpath jar as an argument

Several maven plugins need/support passing a java.io.File as a configuration parameter, wherein we specify the relative/absolute location of the file for the plugin to locate and use. 一些maven插件需要/支持传递java.io.File作为配置参数,其中我们指定文件的相对/绝对位置,以供插件定位和使用。

Is there a way I can specify a property file in the plugin configuration where the file has to be found from inside a jar in the classpath? 有没有一种方法可以在插件配置中指定属性文件,而该文件必须从类路径的jar中找到? I'm particularly wanting this to know and use with the aspectj-maven-plugin , where I can specify the Xlintfile value to be the custom XlinkDefault.properties file location. 我特别想让它知道并与Aspectj-maven-plugin一起使用 ,在这里我可以将Xlintfile值指定为自定义XlinkDefault.properties文件位置。 The file, in my case, will be found inside a classpath jar. 就我而言,该文件将在类路径jar中找到。

I use maven-2.2.1 by the way. 顺便说一下,我使用maven-2.2.1。

No, not in general; 不,一般而言; there's no magic that will turn something that's not a file on disk into a java.io.File . 没有任何魔法可以将磁盘上不是文件的东西变成java.io.File Many Maven plugins (eg, maven-checkstyle-plugin 's configLocation are designed to allow more flexible input for just these cases: 许多Maven插件(例如maven-checkstyle-pluginconfigLocation被设计为仅在以下情况下允许更灵活的输入:

This parameter is resolved as resource, URL, then file. 此参数解析为资源,URL,然后是文件。 If successfully resolved, the contents of the configuration is copied into the ${project.build.directory}/checkstyle-configuration.xml file before being passed to Checkstyle as a configuration. 如果成功解决,则将配置内容复制到$ {project.build.directory} /checkstyle-configuration.xml文件中,然后再将其作为配置传递给Checkstyle。

As a workaround, if the plugin cannot be changed, dependency:unpack may be a way to get a classpath resource into a local file (see Maven: extract files from jar ). 解决方法是,如果无法更改插件,则dependency:unpack可能是将类路径资源获取到本地文件的一种方法(请参阅Maven:从jar中提取文件 )。

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

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