How to fix this POM file to make one fat jar?

fix this POM file to make one fat jar?

You’re on the right track with your pom.xml, but the issue is that you have the <shadedArtifactAttached> option set to true. This tells Maven to generate a separate shaded JAR instead of replacing the default JAR.

How to Fix It

To ensure that only one fat JAR is created (without an extra assignment2-1.0-SNAPSHOT.jar), modify your maven-shade-plugin configuration like this:

Fixed pom.xml

<build>
    <finalName>assignment2</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.10.1</version>
            <configuration>
                <source>17</source>
                <target>17</target>
            </configuration>
        </plugin>

        <!-- Use the Maven Shade Plugin for creating a fat JAR -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.2.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <createDependencyReducedPom>false</createDependencyReducedPom>
                        <shadedArtifactAttached>false</shadedArtifactAttached> 
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>org.example.Main</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Key Fixes

  1. Set <shadedArtifactAttached>false</shadedArtifactAttached>
  • This prevents Maven from generating a separate shaded JAR (assignment2-1.0-SNAPSHOT-shaded.jar) alongside the regular one. Instead, it replaces the default JAR with the fat JAR.
  1. Removed <shadedArtifactClassifier>all</shadedArtifactClassifier>
  • Since we don’t want two different JARs, removing this ensures that only one final JAR is built.

Build Your JAR Again

After making these changes, run:

mvn clean package

This should create only one JAR:

target/assignment2.jar

Now, you can test your program with:

java -jar target/assignment2.jar PDF sample.csv

This should work as expected! Let me know if you need further clarifications.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *