我在用着maven-bundle-plugin
(bnd
有效地)。
从源中包含资源文件很简单。
例如,资源文件(src/main/resources/some.xml
) 移至下面target
目录 (target/classes/some.xml
)在构建期间,可以使用以下命令将其包含到捆绑包中<Include-Resource>
操作说明:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.0.1</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Include-Resource>
some.xml=target/classes/some.xml,
</Include-Resource>
</instructions>
</configuration>
</plugin>
让我们有一个依赖:
<dependency>
<groupId>com.example</groupId>
<artifactId>library</artifactId>
<version>1.0.0</version>
</dependency>
如何引用依赖内部的资源文件jar
?
换句话说,如何
以便来自依赖项之一的资源出现在输出包中jar
?
您可以使用maven-dependency-plugin
解压缩您的依赖项 jar,然后将资源包含在您的 jar 中。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<markersDirectory>${project.build.directory}/dependencies/dependency-maven-plugin-markers</markersDirectory>
<artifactItems>
<artifactItem>
<groupId>DEPENDENCY_GROUPID</groupId>
<artifactId>DEPENDENCY_ARTIFACTID</artifactId>
<type>OPTIONAL_DEPENCENCY_TYPE</type>
<outputDirectory>${project.build.directory}/dependencies/DEPENDENCY_ARTIFACTID</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
...
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
...
<instructions>
...
<Include-Resource>target/dependencies/DEPENDENCY_ARTIFACTID/some.xml</Bundle-Activator>
</instructions>
</configuration>
</plugin>
The Include-Resource
说明应该是 pom 相关的,请参阅包含资源 http://felix.apache.org/documentation/subprojects/apache-felix-maven-bundle-plugin-bnd.html#include-resource,你也许可以替换target
with ${project.build.directory}
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)