【问题标题】:How to add resources of an external jar into my maven build jar?如何将外部 jar 的资源添加到我的 Maven 构建 jar 中?
【发布时间】:2014-02-07 10:22:06
【问题描述】:

我有一个模块,在构建这个模块时,我想将来自外部 jar 的一些资源包含到我的模块 jar 中。

我尝试使用 maven-shade-plugin 但我无法实现它。

感谢任何帮助。

【问题讨论】:

  • 什么资源?类似.properties?
  • 是的,还有一些 .xsb 文件
  • 您有什么特别的理由要这样做吗?您不想将外部 jar 构建到您的模块中?
  • 我只需要外部 jar 中的一些文件。
  • 将外部jar解压到目标中

标签: maven maven-2 maven-plugin


【解决方案1】:

将您的外部资源解压到项目目标中,解压后的资源将包含在生成的工件中。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>unpack</id>
            <phase>process-resources</phase>
            <goals>
                <goal>unpack</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>foo</groupId>
                        <artifactId>bar</artifactId>
                        <version>1.0</version>
                        <type>jar</type>
                        <includes>*.xsb, *.properties</includes>
                    </artifactItem>
                </artifactItems>
                <outputDirectory>${project.build.outputDirectory}</outputDirectory>
                <overWriteReleases>true</overWriteReleases>
                <overWriteSnapshots>true</overWriteSnapshots>
            </configuration>
        </execution>
    </executions>
</plugin>

对于这个答案https://stackoverflow.com/a/3264160/516167的非maven文件使用方法

【讨论】:

  • 感谢您的回答......但我有一个限制,这个外部 jar 不是作为 maven 工件安装的。是否可以给出这个 jar 文件的绝对位置,如 (C:\external.jar) 而不是提及它的 maven 坐标?
猜你喜欢
  • 1970-01-01
  • 2011-07-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-15
  • 2021-10-24
  • 2013-05-14
  • 1970-01-01
相关资源
最近更新 更多