开发者

How can I specify the mainClass in the manifest with minijar-maven-plugin?

开发者 https://www.devze.com 2023-01-09 13:34 出处:网络
I\'m using the minijar-maven-plugin to reduce the size of my jar-with-dependencies jar but I need to specify a mainClass lik开发者_StackOverflow社区e I can do easily with the maven assembly plugin. Ho

I'm using the minijar-maven-plugin to reduce the size of my jar-with-dependencies jar but I need to specify a mainClass lik开发者_StackOverflow社区e 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>


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.


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

精彩评论

暂无评论...
验证码 换一张
取 消