Question

I'm using several libraries in my java application.

In the pom.xml the proguard maven plugin includes them like so:

<inclusion>
    <groupId>javafx</groupId>
    <artifactId>jfxrt</artifactId>
    <library>true</library>
    <filter>!META-INF/**</filter>
</inclusion>

I noticed, that only when I include libraries with <library> set to true, the manifest file gets replaced, allthough I specify the <filter> for all libraries. But I need to include them with <library> set to true, since otherwise some of them don't work.

Now after building the jar, it won't start, because the Manifest doesn't contain the path to the main class any more.

I found two approaches, to solve this. However, both don't work.

First approach:

    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.3</version>
    <executions>
        <execution>
            <phase>install</phase>
            <configuration>
                <tasks>
                    <echo
                        message="Adding Manifest to  ${project.build.directory}/${my.outfilename}.jar" />
                    <manifest file="META-INF/MANIFEST.MF" mode="replace">
                        <attribute name="Manifest-Version" value="1.0" />
                        <attribute name="Package"
                            value="com.xyz.mypackage" />
                        <attribute name="Main-Class" value="MyMainClass" />
                        <attribute name="Version"
                            value="${my.version.main}${my.version.sub}" />
                    </manifest>
                </tasks>
            </configuration>
        </execution>
    </executions>
</plugin>

Nothing happens at all. I've set <phase> to install and deploy. Both have no effect.

Second approach:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.4</version>
    <executions>
        <execution>
            <phase>deploy</phase>
            <configuration>
                <archive>
                    <manifestFile>${basedir}/build/MANIFEST.MF</manifestFile>
                </archive>
            </configuration>
        </execution>
    </executions>
</plugin>

This also doesn't change anything. Even with -X to get a debug output I can't see that one of the plugins is ever executed. Both <plugin> sections are inside <build><plugins></plugins></build>

Now I'm really stuck, since manually changing the Manifest file after the jar has been built is not acceptable in an automated build process.

Hope you can help. Thanks!

Was it helpful?

Solution

Took me days to figure this out. Actually it's quite simple though:

In the <configuration> section of the proguard-maven-plugin just add this:

<archive>
     <manifest>
        <mainClass>MyMainClass</mainClass>
        <packageName>com.xyz.abc</packageName>
    </manifest>
</archive>

This will add a line in the Manifest, which contains the specified Main class

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top