Maven: Generate JAR with Dependencies / Directory recources

4

I am very lazy with Maven and because there is a lot of material on the internet I end up getting lost as I perform the operation below:

I need to generate the JAR Runnable of my project with all the dependencies I have used and also the java/main/resources/META-INF folder.

Below is the directory tree for my project.

    
asked by anonymous 22.09.2015 / 22:30

1 answer

1

Come on !!

After a lot of meaningless search on Google, I ended up finding 3 links that helped me generate my JAR with the Dependencies / Custom Libraries / Directories Resources. Here's the link sequence you'll find in each of the sources.

Source 1: Add JARs themselves or downloaded from the internet to the Maven Repository Location: MkYoung.com | Add JAR to Maven Local Repository

Source 2: Configure the Maven-Shade-Plugin to find the Spring Main and Spring Boot. link

Source 3: Own site of Apache Maven with ways to add a JAR to the local Maven repository.

link

Simplifying my Build of Pom.xml is as follows:

<build>
    <finalName>SisAcademia</finalName>
    <sourceDirectory>src/main/java</sourceDirectory>
    <testSourceDirectory>src/main/test</testSourceDirectory>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <!-- Optional Start -->
                        <finalName>SisAcademia</finalName>
                        <shadedArtifactAttached>true</shadedArtifactAttached>
                        <shadedClassifierName>jar-with-dependencies</shadedClassifierName>
                        <!-- Optional End -->

                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>br.com.tamarozzi.app.Main</mainClass>
                            </transformer>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.handlers</resource>
                            </transformer>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.schemas</resource>
                            </transformer>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.tooling</resource>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
    
23.09.2015 / 16:14