Maven War Plugin - 从另一个 jar 添加外部资源

发布于 2024-08-26 19:09:18 字数 122 浏览 4 评论 0原文

如果我想从另一个 jar 中提取资源,比如图像或 XML 文件,这可能吗?我会使用 Maven Assembly Plugin 或 War Plugin 来执行此操作吗?我希望它最终出现在 WAR 文件中。

沃尔特

If I wanted to pull out a resource from another jar, say an image or XML file, is that possible? Would I use the Maven Assembly Plugin or the War Plugin to do this? I want it to end up in a WAR file.

Walter

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧城空念 2024-09-02 19:09:18

您可以在 war 模块中使用 Dependency 插件并绑定 dependency:unpack 目标是generate-resources 阶段。查看解压特定工件示例。

You could use the Dependency plugin in your war module and bind the dependency:unpack goal to the generate-resources phase. Check the Unpacking specific artifacts example.

春庭雪 2024-09-02 19:09:18

我想从 artefactory 中提取一些资源用于其他项目,我们需要 2 个插件 maven-dependency-plugin 来提取,maven-clean-plugin 来清理项目。调用第一个插件执行目标依赖项:unpack。

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>com.company.artifactory</artifactId>
                        <version>${project.version}</version>
                        <type>jar</type>
                        <overWrite>true</overWrite>
                        <includes>dirInsideJar/**/*.*</includes>
                        <outputDirectory>src/main/resources</outputDirectory>
                    </artifactItem>
                </artifactItems>
                <!-- other configurations here -->
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <filesets>
                    <fileset>
                        <directory>src/main/resources/dirInsideJar</directory>
                    </fileset>
                </filesets>
            </configuration>
        </plugin>

上面的用法在 this 中有解释文章

I want to extract some resource form artefactory to used in other proyect, we need 2 plugins maven-dependency-plugin to extract and maven-clean-plugin to clean proyect. call first plugin execute the goal dependency:unpack.

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>${project.groupId}</groupId>
                        <artifactId>com.company.artifactory</artifactId>
                        <version>${project.version}</version>
                        <type>jar</type>
                        <overWrite>true</overWrite>
                        <includes>dirInsideJar/**/*.*</includes>
                        <outputDirectory>src/main/resources</outputDirectory>
                    </artifactItem>
                </artifactItems>
                <!-- other configurations here -->
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <version>2.5</version>
            <configuration>
                <filesets>
                    <fileset>
                        <directory>src/main/resources/dirInsideJar</directory>
                    </fileset>
                </filesets>
            </configuration>
        </plugin>

The usage of the above is explained in this article.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文