Maven: Generate JAR with Dependencies / Directory recources

Asked

Viewed 1,940 times

4

I’m very lay with Maven and the fact that there is a lot of material on the Internet I ended up getting lost as I perform the operation below:

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

Whoever will explain me, please start from the point that I have extreme low knowledge in Maven/Pom.xml, what I’ve been seeing is necessary to build a plug with the project configuration.

Follow below the directory tree of my project.

inserir a descrição da imagem aqui

  • 1

    To generate an "executable", you have that answer with build configuration. In my case solved.

  • @Renan your tip was useful, but still intended lack how to make application recognize the folders 'Resources' which in my case contain configuration files and images.

  • What is your IDE ?

  • @Davidschrammel sorry to have not informed, I use the Eclipse but I managed to perform the procedure with the information of the 'right' answer below.

  • Cool, in the eclipse Luna you can right click and export, will open a screen and you can mark to export the dependencies together in the jar.

1 answer

1


Come on!!

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

Source 1: Add own or downloaded JAR to Local Maven Repository: Mkyoung.com | Add JAR to Local Maven Repository

Source 2: Configure the Maven-Shade-Plugin to find the Main Class and Spring Boot. http://crunchify.com

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

https://maven.apache.org

Simplifying my Build of Pom.xml was the following below:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.