如何使用 maven- assembly-plugin (或其他方式)将外部工件组装到一个全局目录中

发布于 2024-11-05 07:31:48 字数 1812 浏览 4 评论 0原文

我正在尝试使用 Maven,并尝试将最初使用 shell 脚本构建的项目进行 mavenize。

根据 Maven 的经验法则:一个项目,一个工件,我创建了以下结构:

<PROJECT>
  <MODULE-1>
  <MODULE-2>
  <MODULE-3>
  ..
  <MODULE-N>
  <RESOURCES>     
  <DISTRIB>

RESOURCES 模块的结构如下:

<RESOURCES>/src/main/resources/<MODULE-1>/bin
<RESOURCES>/src/main/resources/<MODULE-1>/lib
<RESOURCES>/src/main/resources/<MODULE-1>/doc
<RESOURCES>/src/main/resources/<MODULE-2>/bin
<RESOURCES>/src/main/resources/<MODULE-2>/lib
<RESOURCES>/src/main/resources/<MODULE-2>/doc
...
<RESOURCES>/src/main/resources/<MODULE-N>/bin
<RESOURCES>/src/main/resources/<MODULE-N>/lib
<RESOURCES>/src/main/resources/<MODULE-N>/doc

这样做的原因是上面的资源是在运行时而不是编译时需要的它们主要是属性文件、配置文件和调用各种 jar 文件的 shell 脚本。对于最后的资源步骤,我想将子目录合并到一个全局 bin/lib/doc 目录中。但是,我在程序集描述符中没有看到一个选项可以去除模块的前缀以获得我想要的内容:

 <RESOURCES>/target/resources/bin
 <RESOURCES>/target/resources/lib
 <RESOURCES>/target/resources/doc

其中 bin 将包含 /src/main/resources 中找到的所有文件//bin 目录、/src/main/resources//bin 目录等。libdoc 类似。

我的问题:我应该有一个:

<MODULE-1>/src/external/resources/bin
<MODULE-1>/src/external/resources/lib
<MODULE-1>/src/external/resources/doc
...
<MODULE-N>/src/external/resources/bin
<MODULE-N>/src/external/resources/lib
<MODULE-N>/src/external/resources/doc

结构,然后我可以通过依赖集访问它吗?这些文件不应该是各个模块的 jar 文件的一部分,因此不能存储在各自项目的 src/main/resources 中。或者我想通过使用其他 Maven 插件来实现什么?

在 DISTRIB 模块中,我将 RESOURCES 模块的输出与 JAR 文件和依赖项结合起来,创建一个目录结构,然后将其与打包工具(Solaris 包和 WiX 安装程序)一起使用。

任何帮助将不胜感激!

I am experimenting with Maven and I am trying to mavenize a project originally build with shell scripts.

With the Maven rule-of-thumb: one project, one artifact, I created the following structure:

<PROJECT>
  <MODULE-1>
  <MODULE-2>
  <MODULE-3>
  ..
  <MODULE-N>
  <RESOURCES>     
  <DISTRIB>

The RESOURCES module is structured as follows:

<RESOURCES>/src/main/resources/<MODULE-1>/bin
<RESOURCES>/src/main/resources/<MODULE-1>/lib
<RESOURCES>/src/main/resources/<MODULE-1>/doc
<RESOURCES>/src/main/resources/<MODULE-2>/bin
<RESOURCES>/src/main/resources/<MODULE-2>/lib
<RESOURCES>/src/main/resources/<MODULE-2>/doc
...
<RESOURCES>/src/main/resources/<MODULE-N>/bin
<RESOURCES>/src/main/resources/<MODULE-N>/lib
<RESOURCES>/src/main/resources/<MODULE-N>/doc

The reason for doing it this way was that the resources above are needed at runtime, not compile-time and they are mostly property files, config files and shell scripts to invoke the various jar-files. For the final resources step, I wanted to combine the subdirectories into one global bin/lib/doc directory. However, I do not see an option in the assembly descriptor to strip of the prefix of the modules to get to what I want:

 <RESOURCES>/target/resources/bin
 <RESOURCES>/target/resources/lib
 <RESOURCES>/target/resources/doc

where bin would contain all the files found in the /src/main/resources//bin directory, /src/main/resources//bin directory etc. Similarly for lib, doc.

My question: should I have a:

<MODULE-1>/src/external/resources/bin
<MODULE-1>/src/external/resources/lib
<MODULE-1>/src/external/resources/doc
...
<MODULE-N>/src/external/resources/bin
<MODULE-N>/src/external/resources/lib
<MODULE-N>/src/external/resources/doc

structure instead, that I would then access through a dependency-set? These files should not be part of the jar-file of the various modules and therefore cannot be stored in src/main/resources of their respective projects. Or is what I want to achieve doable by using some other maven plugin instead?

In the DISTRIB module I would combine the output of the RESOURCES module with the JAR-files and dependencies to create a directory structure that would then be used with a packaging tool (Solaris package and WiX installer).

Any help would be appreciated!

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

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

发布评论

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

评论(1

享受孤独 2024-11-12 07:31:48

在 pom 堡垒中,资源模块将源目录设置为 /src/main/resources/ 以外的目录,以便它不会将它们复制到目标文件夹。然后使用 Maven Resources Plugin 将资源文件复制到 target/bin 并目标库等,

例如

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.4.3</version>
    <executions>
        <execution>
            <id>copy-resources</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>target/bin/</outputDirectory>
                <resources>
                    <resource>
            <directory>src/external/resources/bin</directory>
                <filtering>false</filtering>
        </resource>
        </resources>
    </configuration>
    </execution>
        <execution>
            <id>copy-resources</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>target/lib/</outputDirectory>
                <resources>
                    <resource>
            <directory>src/external/resources/lib</directory>
                <filtering>false</filtering>
        </resource>
        </resources>
    </configuration>
    </execution>
    </executions>
</plugin>`

In the pom fort he resources module set the source directory to something other than /src/main/resources/ so that it does not copy them to the target folder. Then use the Maven Resources Plugin to copy the resource files to target/bin and target lib etc.

e.g.

<plugin>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.4.3</version>
    <executions>
        <execution>
            <id>copy-resources</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>target/bin/</outputDirectory>
                <resources>
                    <resource>
            <directory>src/external/resources/bin</directory>
                <filtering>false</filtering>
        </resource>
        </resources>
    </configuration>
    </execution>
        <execution>
            <id>copy-resources</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <outputDirectory>target/lib/</outputDirectory>
                <resources>
                    <resource>
            <directory>src/external/resources/lib</directory>
                <filtering>false</filtering>
        </resource>
        </resources>
    </configuration>
    </execution>
    </executions>
</plugin>`
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文