Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add classpath to manifest with a custom assembly descriptor

I have the following custom assembly:

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

And the following configuration section:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
        <descriptors>
            <descriptor>src/main/assembly/assembly.xml</descriptor>
        </descriptors>
        <archive>
            <manifest>
                <mainClass>com.example.MyExample</mainClass>
                <addClasspath>true</addClasspath>
                <classpathPrefix>./lib/</classpathPrefix>
            </manifest>
        </archive>
    </configuration>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

According to the documentation on the maven assembly plugin, this should add a classpath item to the manifest file, however it does not work. If I use the deprecated assembly goal instead of single, it does work.

I noticed somewhere someone mentioned that the archive section is only available with the jar format, but that is what I'm using.

When they deprecated assembly:assembly, did they define a new way of doing this correctly? I really don't like using deprecated functionality, but if they break the way things worked and don't properly document it, I really don't know how to avoid this.

Does anyone have any examples of how to do this properly?

like image 990
davija Avatar asked Sep 14 '11 00:09

davija


People also ask

How to add classpath in manifest file using Maven?

Add A Class-Path Entry To The Manifest Maven Archiver can add the classpath of your project to the manifest. This is done with the <addClasspath> configuration element.

What is assembly descriptor in Maven?

This descriptor specifies the type of assembly archive to create, the contents of the assembly, and the ways in which dependencies or its modules are bundled with an assembly. <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

What is manifest file in Maven?

Tags:manifest | maven. This tutorial will show you how to use the maven-jar-plugin to create a manifest file, and package / add it into the final jar file. The manifest file is normally used to define following tasks : Define the entry point of the Application, make the Jar executable. Add project dependency classpath.

What is Maven Assembly plugin?

The Assembly Plugin for Maven enables developers to combine project output into a single distributable archive that also contains dependencies, modules, site documentation, and other files. Your project can easily build distribution "assemblies" using one of the prefabricated assembly descriptors.


1 Answers

This is not a good use of the assembly plugin. Java doesn't do jars-in-jars. You can use the maven-jar-plugin's configuration options to add a classpath to the manifest of your main jar, and then use the assembly plugin to collect your dependencies and drop then next to your main jar in a zip or tarball.

http://maven.apache.org/shared/maven-archiver/examples/classpath.html

like image 172
bmargulies Avatar answered Oct 08 '22 15:10

bmargulies