是否可以重命名带有依赖项的Maven jar? [英] Is it possible to rename a maven jar-with-dependencies?

查看:636
本文介绍了是否可以重命名带有依赖项的Maven jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用jar-with-dependencies程序集来创建这样的jar.但是,我的罐子的名称有点长.

I'm currently using the jar-with-dependencies assembly to create such a jar. However, the name of my jar is a bit long.

由于AS400上的RPG程序正在使用此jar,因此我想缩短它,以使这些开发人员的工作变得更轻松.但是,除了手工之外,我还没有找到一种从通常的project-name-version-classifier-jar-with-dependencies.jar重命名jar的方法.我想要类似project-name-version-classifier-full.jar

Since this jar is being used by RPG programs on an AS400, I'd like to shorten it to make life a bit easier for those developers. But, other than by hand, I've not found a way to rename the jar from the usual project-name-version-classifier-jar-with-dependencies.jar. I'd like something like project-name-version-classifier-full.jar

有没有这样做,而基本上没有复制jar-with-dependencies程序集描述符并完全调用它?

Is there anyway to do this without basically copying the jar-with-dependencies assembly descriptor and calling it full?

此外,我想继续将没有组装好的类路径的jar存储在存储库中.

Additionally, I want to continue to have the jar without the classpath assembled stored in the repository.

我需要两个工件.具有我的分类器的jar包含构建所针对的区域.具有所有依赖项的jar,其中还包括区域.

I need two artifacts. The jar with my classifier holding the region which the build is for. The jar with all dependencies which also includes the region.

project-name-version-region-full.jarproject-name-version-region.jar应该存储在存储库中.在第一个示例中,分类器是全区域的,在第二个示例中是区域.后者正在工作.

project-name-version-region-full.jar and project-name-version-region.jar should be stored in the repository. In the first example the classifier is region-full, in the 2nd it's region. The latter is working.

推荐答案

您可以指定 finalName 属性为罐子指定所需的名称,并指定 appendAssemblyId 为避免后缀"jar-with-dependencies",应该为假.

You can specify the finalName property to give the jar the name you want, and specify that appendAssemblyId should be false to avoid the "jar-with-dependencies" suffix.

下面的配置将输出一个名为"test.jar"的jar

The configuration below will output a jar called "test.jar"

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>2.2-beta-4</version>
  <executions>
    <execution>
      <id>jar-with-dependencies</id>
      <phase>package</phase>
      <goals>
        <goal>single</goal>
      </goals>
      <configuration>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        <finalName>test</finalName>
        <appendAssemblyId>false</appendAssemblyId>
      </configuration>
    </execution>
  </executions>
</plugin>


更新:根据您的评论,无法使用内置描述符.我认为这归结于最新版本的Assembly-Plug中的一个错误-他们已经删除了对分类器的支持,但是如果您使用内置描述符,则ID是固定的,因此您会以一个笨拙的名字结尾.


Update: based on your comments, using the built-in descriptor won't work . I believe this is down to a bug in the recent versions of the assembly-plugin - they've removed support for classifiers, but the id is fixed if you use a built-in descriptor, so you end up with a big daft name.

作为一种解决方法,您可以复制具有依赖项的jar 描述符并修改ID.

As a workaround, you can copy the assembly descriptor used by the jar-with-dependencies descriptor and modify the id.

此示例将导致程序集ID附加到finalName,因此,如果您需要具有 region-full.jar 的名称,则可以将finalName指定为 region ,并且程序集ID为 full .这将在目标中生成一个名为region-full.jar的文件,但请注意,该文件仍将作为附件与 full 一起用作分类器安装到Maven存储库中.只要此ID与其他程序集的ID不同,就应该没有碰撞.

This example would result in the assembly id being appended to the finalName, so if you need to have a name of region-full.jar, you can specify the finalName as region and the assembly id as full. This will result in a file in target called region-full.jar, but note it will still be installed to the Maven repository as an attached artifact with full used as the classifier. As long as this id is different to that for your other assembly there should be no collision though.

pom配置如下所示.

The pom configuration would look like this.

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>2.2-beta-4</version>
  <executions>
    <execution>
      <id>jar-with-dependencies</id>
      <phase>prepare-package</phase>
      <goals>
        <goal>single</goal>
      </goals>
      <configuration>
        <descriptors>
          <descriptor>src/main/assembly/jar-assembly.xml</descriptor>
        </descriptors>
        <finalName>region</finalName>
      </configuration>
    </execution>
  </executions>
</plugin>

以及src/main/assembly中的jar-assembly.xml,如下所示:

and the jar-assembly.xml in src/main/assembly like this:

<assembly>
  <id>full</id>
  <formats>
    <format>jar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
    <dependencySet>
      <unpack>true</unpack>
      <scope>runtime</scope>
    </dependencySet>
  </dependencySets>
  <fileSets>
    <fileSet>
      <directory>${project.build.outputDirectory}</directory>
    </fileSet>
  </fileSets>
</assembly>

这篇关于是否可以重命名带有依赖项的Maven jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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