maven 程序集依赖项设置为空

发布于 2024-12-04 00:28:39 字数 2099 浏览 1 评论 0原文

我正在尝试设置一个我认为简单的程序集,从多个模块中获取 jar 并将它们放入 zip 内的特定文件夹中。生成的程序集应如下所示:
ir4job\
ir4job\app_lib\
ir4job\app_lib\ jar 文件放在这里

但是当生成程序集时,maven 给了我一个空的 zip 文件 程序

集描述符:

<assembly>
  <!-- ir4job folder contents -->
  <id>ir4job-app</id>
  <formats>
    <format>zip</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>

  <moduleSets>
    <moduleSet>
      <binaries>
        <dependencySets>
          <dependencySet>
            <outputDirectory>ir4job/app_lib</outputDirectory>
          </dependencySet>
        </dependencySets>
      </binaries>
    </moduleSet>
  </moduleSets>
</assembly>

pom 文件:

<project>
  <modelVersion>4.0.0</modelVersion>

  <groupId>glb</groupId>
  <artifactId>Release</artifactId>
  <packaging>pom</packaging>
  <name>release</name>
  <version>1.0</version>

  <parent>
.... parent info ....
  </parent>

  <dependencies>
... various dependencies ...
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>

        <configuration>
          <appendAssemblyId>false</appendAssemblyId>
          <descriptors>
            <descriptor>ir4job-app.xml</descriptor>
          </descriptors>
        </configuration>
        <executions>
          <execution>
            <id>do-release</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>
</project>

我很确定我在这里错过了一些简单的东西...它是什么?

Im trying to setup what I think is a simple assembly, taking the jars from several modules and putting them in a specific folder inside a zip. The resulting assembly should look like so:
ir4job\
ir4job\app_lib\
ir4job\app_lib\ jar files go here

But maven is giving me an empty zip file when the assembly is generated

Assembly descriptor:

<assembly>
  <!-- ir4job folder contents -->
  <id>ir4job-app</id>
  <formats>
    <format>zip</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>

  <moduleSets>
    <moduleSet>
      <binaries>
        <dependencySets>
          <dependencySet>
            <outputDirectory>ir4job/app_lib</outputDirectory>
          </dependencySet>
        </dependencySets>
      </binaries>
    </moduleSet>
  </moduleSets>
</assembly>

pom file:

<project>
  <modelVersion>4.0.0</modelVersion>

  <groupId>glb</groupId>
  <artifactId>Release</artifactId>
  <packaging>pom</packaging>
  <name>release</name>
  <version>1.0</version>

  <parent>
.... parent info ....
  </parent>

  <dependencies>
... various dependencies ...
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>

        <configuration>
          <appendAssemblyId>false</appendAssemblyId>
          <descriptors>
            <descriptor>ir4job-app.xml</descriptor>
          </descriptors>
        </configuration>
        <executions>
          <execution>
            <id>do-release</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>
</project>

Im pretty sure I missed something simple here... what is it?

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

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

发布评论

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

评论(1

清风夜微凉 2024-12-11 00:28:39

乍一看,您似乎缺少要包含的文件集。例如:

<assembly>
    <id>ir4job-app</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>

    <fileSets>
        <fileSet>
            <directory>path/to/folder/relative/to/project/root/ir4job/app_lib</directory>
            <outputDirectory>ir4job/app_lib</outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>

您需要为要包含的每个目录提供一个文件集(除非它们位于同一父目录下)。其语法类似于:

...
<includeBaseDirectory>true</includeBaseDirectory>
....
<fileSet>
    <directory>path/to/folder/relative/to/project/root/ir4job</directory>
    <includes>
        <include>**/*.jar</include>
    </includes>
</fileSet>
...

edit #1:

使用 maven-dependency-plugin 将依赖项复制到文件夹的工作示例:

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-dependencies-for-assembly</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>target/libs</outputDirectory>
                        <stripVersion>true</stripVersion>
                    </configuration>
                </execution>
            </executions>
        </plugin>

注意:您还可以使用配置选项来限制复制的依赖项,例如

...
<configuration>
    ...
    <includeGroupIds>com.mycompany,org.springframework,org.hibernate</includeGroupIds>
</configuration>
...

You can also limit by artifactId、分类器等


编辑#2:

解决方案

更好的答案可能只是将您的 dependencySet 标记拉高几个级别,如下所示:

<assembly>
    <!-- ir4job folder contents -->
    <id>ir4job-app</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>

    <dependencySets>
        <dependencySet>
            <outputDirectory>ir4job/app_lib</outputDirectory>
        </dependencySet>
    </dependencySets>
 </assembly>

At first glance, it seems you are missing the filesets to include. For example:

<assembly>
    <id>ir4job-app</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>

    <fileSets>
        <fileSet>
            <directory>path/to/folder/relative/to/project/root/ir4job/app_lib</directory>
            <outputDirectory>ir4job/app_lib</outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>

You will need a fileset for each directory you want to include (unless they fall under the same parent directory). The syntax for that is something like:

...
<includeBaseDirectory>true</includeBaseDirectory>
....
<fileSet>
    <directory>path/to/folder/relative/to/project/root/ir4job</directory>
    <includes>
        <include>**/*.jar</include>
    </includes>
</fileSet>
...

edit #1:

Working example of using the maven-dependency-plugin to copy dependencies to a folder:

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-dependencies-for-assembly</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>target/libs</outputDirectory>
                        <stripVersion>true</stripVersion>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Note: you can also limit the dependencies that get copied using configuration options such as

...
<configuration>
    ...
    <includeGroupIds>com.mycompany,org.springframework,org.hibernate</includeGroupIds>
</configuration>
...

You can also limit by artifactId, classifier, etc.


edit #2:

Solution

The better answer is probably just to pull your dependencySet tag up a couple levels as in:

<assembly>
    <!-- ir4job folder contents -->
    <id>ir4job-app</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>

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