Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to build a semi-fat jar using maven in JAVA

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 329
    Answer it

    For my project, I have used the below configuration to generate the thin jar

     

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
            <archive>
                <manifest>
                    <mainClass>
                        com.aaa.bbb.MainClass
                    </mainClass>
                </manifest>
            </archive>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
            <execution>
                <id>copy-dependencies</id>
                <phase>package</phase>
                <goals>
                    <goal>copy-dependencies</goal>
                </goals>
                <configuration>
                    <outputDirectory>${project.build.directory}/libs</outputDirectory>
                    <includeScope>compile</includeScope>
                </configuration>
            </execution>
        </executions>
    </plugin>

    My jar is created without the dependent jars and using maven copy commands all the jars get copied into the respective folders.

    Going forward I need to separate some selected jars from external jars, I have below two options

    1. I want to add some selected jars(some other jars from the related project) to be a part of the main jar and exclude the external jars like hibernate, springfox, etc.. creating a semi-fat jar. But don't know to add some selected jars to be a part of main jar.
    2. The selected jars can be placed in a folder inside the target folder(the main jar is still a thin jar) and then use the maven copy command to download only the external jars.

     

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: