Maven程序集将当前项目jar包含在最终的zip/tar中 [英] maven assembly include the current project jar in the final zip/tar

查看:152
本文介绍了Maven程序集将当前项目jar包含在最终的zip/tar中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用maven程序集插件生成一个.tar文件,该文件包含其他几个文件(从属jar).所有文件都已正确复制到配置assembly.xml中的给定文件夹中.

I am using maven assembly plugin to generate a .tar file contain several other files, dependent jars. All the files are being copied correctly to the given folders in the config assembly.xml.

我也希望将原始项目jar也包含在最终的tar文件中,但目前看不到它.

I would like to include the original project jar too in the final tar file, but not seeing it currently in it.

我发出assembly:single目标时确实收到以下消息:

I do get the following message when I issue assembly:single goal:

[警告]无法包含项目工件:com.my.newpkg.project1:jar:0.0.3.0;它没有关联的文件或目录.

[WARNING] Cannot include project artifact: com.my.newpkg.project1:jar:0.0.3.0; it doesn't have an associated file or directory.

在阅读完SO之后,似乎将以下配置添加到pom.xml应该会添加jar,但仍然无法获得预期的结果.

After reading over SO, it seems adding the following configs to pom.xml should add the jar, but still not getting the expected result.

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-jar-plugin</artifactId>
   <version>2.4</version>
   <configuration>
       <archive>
           <manifest>
               <mainClass>com.my.newpkg.project1.MainClass</mainClass>
               <addClasspath>true</addClasspath>
               <classpathPrefix>lib/</classpathPrefix>
           </manifest>
       </archive>
   </configuration>
</plugin>

assembly.xml片段

<formats>
    <format>dir</format>
    <format>tar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
    <dependencySet>
        <outputDirectory>lib</outputDirectory>
        <excludes>
            <exclude>junit:junit</exclude>
        </excludes>
        <fileMode>0755</fileMode>
    </dependencySet>
</dependencySets>

那么,配置还不正确吗?还是我在这里想念东西?

So, the configs are not yet correct? or Am I missing something here?

如何将当前的项目jar添加到最终的tar中

How can we add the current project jar into the final tar

推荐答案

<dependencySet>中,您可以通过说出<useProjectArtifact>false</useProjectArtifact>来排除当前项目jar,但是默认情况下它是正确的,因此应该可以使用.

In <dependencySet> you can exclude the current project jar by saying <useProjectArtifact>false</useProjectArtifact>, but it's true by default, so it should work.

根据警告,我想您首先忘记做mvn package,因此该jar文件在目标目录中不可用.

From the warning, I guess you forgot to do mvn package first, so the jar is not available from the target directory.

或者在一个命令中执行mvn package assembly:single.

Or do mvn package assembly:single in one command.

或者,在您的pom中添加maven-assembly-plugin并将其绑定到'package'阶段,这样它将在mvn package上自动触发:

Alternatively, add maven-assembly-plugin in your pom and bind it to the 'package' phase so it will trigger automatically on mvn package:

   <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <id>tar-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <descriptors>
                <descriptor>etc/assembly.xml</descriptor>
              </descriptors>
            </configuration>
          </execution>
        </executions>
      </plugin>

这篇关于Maven程序集将当前项目jar包含在最终的zip/tar中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆