tags:

views:

2248

answers:

2

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

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

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

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

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.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.

+4  A: 

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.

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>


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.

As a workaround, you can copy the assembly descriptor used by the jar-with-dependencies descriptor and modify the 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.

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>

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>
Rich Seller
Ah, appendAssemblyId, how did I miss you. Thanks!
Mike Cornell
Unaccepting, due to an unexpected issue.
Mike Cornell
can you elaborate?
Rich Seller
Working on that elaboration Rich. Essentially, I need two classifier artifacts to be stored. With appendAssemblyId turned on, I had 3 artifiacts, one without classifier, the classifier version, and the jar-with-dependencies version. with appendAssemblyID turned off the uber jar is installed to the non-classifier version. I need to have these guys use a region+full based classifier that says where they were built for. Unfortunately adding the classifier tag does not work.
Mike Cornell
Full credit to you Rich. Two changes to your solution got me exactly what I needed. Thx.
Mike Cornell
A: 

I'm going to give Rich the credit for pointing me in the right direction, but wanted to post the solution that worked for me as Rich's was slightly off:

My jar-assembly.xml looked like this which allowed the assembly id to change for the region which was stored as an property in my profile:

<assembly>
  <id>${env}-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>

I did not use the finalName parameter in the maven-assembly-plugin settings as this built my project with my project-name-version-env-full.jar name where env-full was the classifier.

Imagine my surprise when I learned the assembly xml could be parameterized by items in the build. This was exactly what I was looking for.

Mike Cornell