views:

765

answers:

3

Hi I have configured my assembly descriptor to have an assembly of type jar by

<formats>
  <format>jar</format>
</formats>

However,on running mvn install getting zip files instead of jar.Where I have gone wrong?

+1  A: 

Why don't you use the pre-defined assembly jar-with-dependencies? Below the descriptor file:

<assembly>
  <id>jar-with-dependencies</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>

To use assembly:assembly using a predefined descriptor, run:

mvn assembly:assembly -DdescriptorId=jar-with-dependencies

To produce the assembly as part of the normal build cycle, bind the single or single-directory mojo to the package phase (see Usage):

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2-beta-5</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id> <!-- this is used for inheritance merges -->
            <phase>package</phase> <!-- append to the packaging phase. -->
            <goals>
              <goal>single</goal> <!-- goals == mojos -->
            </goals>
          </execution>
        </executions>
      </plugin>
      [...]
</project>
Pascal Thivent
that descriptor will bundle all dependencies of the project in the jar, this is not always what is wanted
Rich Seller
Where did you get this link? It is different than what is on the Maven site: http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html#jar-with-dependencies
User1
@User1 Google's fault :) I was indeed pointing on a very old version of the documentation. Thanks for pointing that out.
Pascal Thivent
I ask because the one on Maven's site doesn't seem to build a jar-with-dependencies either. I had to use the one you point to and add outputFileNameMapping as an empty string in the dependencySet. Maybe you know someone we can tell.
User1
@User1 Actually, you shouldn't have to provide the assembly descriptor explicitly when using a predefined descriptor, only its name. That's weird. I'm going to test this.
Pascal Thivent
Let me know what you find. It's a good useful baseline if you want to create a jar but not every dependency in your project.
User1
+1  A: 

This configuration produces a jar assembly with the classifier jar-assembly containing only the contents of target/classes. You can add additional filesets if needed to add other content to the jar. To ensure you don't have zip archives from any previous runs in your target directory, you can delete it or run mvn clean.

<assembly>
  <id>jar-assembly</id>
  <formats>
    <format>jar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <fileSets>
    <fileSet>
      <directory>${project.build.outputDirectory}</directory>
      <outputDirectory>/</outputDirectory>
    </fileSet>
  </fileSets>
</assembly>

The plugin configuration should look something like this. Note setting appendAssemblyId to false will cause the default jar to be replaced by the jar from the assembly, remove that element if this is not the desired behaviour:

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>2.2-beta-2</version>
  <executions>
    <execution>
      <phase>package</phase>
      <goals>
        <goal>single</goal>
      </goals>
      <configuration>
        <appendAssemblyId>false</appendAssemblyId>
        <descriptors>
          <descriptor>src/main/assembly/archive.xml</descriptor>
        </descriptors>
      </configuration>
    </execution>
  </executions>
</plugin>
Rich Seller
A: 

Thanks for the replies.I used the configuration with the classifier jar-assembly and it worked for me

@unknown if you find an answer useful, you can upvote it or accept it by clicking on the upwards-pointing triangle and/or the tick next to it. You should also avoid "answering" your own question with comments like this, instead click on *add comment* under an answer, or if you are providing more information you can modify your question.
Rich Seller