views:

52

answers:

2

I'm using the minijar-maven-plugin to reduce the size of my jar-with-dependencies jar but I need to specify a mainClass like I can do easily with the maven assembly plugin. How can i specify the mainClass in the manifest while still using the minijar plugin?

My minijar configuration is the default:

    <plugin>
        <artifactId>minijar-maven-plugin</artifactId>
        <groupId>org.codehaus.mojo</groupId>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>ueberjar</goal>
                </goals>
                <configuration>
                    <includeArtifact>true</includeArtifact>
                    <stripUnusedClasses>false</stripUnusedClasses>
                    <includeDependencies>
                        <param>org.vafer:dependency</param>
                    </includeDependencies>
                    <includeDependenciesInRelocation>
                        <param>org.vafer:dependency</param>
                    </includeDependenciesInRelocation>
                </configuration>
            </execution>
        </executions>
    </plugin>

I can specify the main class in a maven assembly plugin using:

    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
            <archive>
                <manifest>
                    <mainClass>com.chheng.Main</mainClass>
                </manifest>
            </archive>
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
        </configuration>
    </plugin>
A: 

This has been requested - see this executable uberjar thread and MOJO-852 - but is still not supported. And given that this issue is open for more than 3 years now, I would not expect a fast resolution (unless you submit a patch).


I don't know the minijar plugin very well, I never used it actually... but what happens if you configure the jar plugin to generate a manifest with the main-class entry for the main jar?

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <configuration>
    <archive>
      <manifest>
        <!--addClasspath>true</addClasspath-->
        <mainClass>my.main.Class</mainClass>
        </manifest>
    </archive>
  </configuration>
</plugin>
Pascal Thivent
Thanks for linking the mojo ticket. I created a reward for anyone who can submit a patch for it. http://nextsprocket.com/tasks/mojo-852-add-manifest-file-in-minijar-ueberjar
tommy chheng
+1  A: 

You should try the maven shade plugin. It deals better with metadata and also take care of the dependency inlining.

I've deprecated the minijar plugin and instead added support for the same optimizatiosn to the maven shade plugin.

Watch/vote for this issue to get it applied.

tcurdt