Please tell me, is it possible to build a project in maven so that all third-party libraries that we connect to pom.xml automatically loaded into it and you can safely run the program?

I know that such plug-ins like maven-shade-plugin and maven-assembly-plugin can help, but since I just started studying maven I can’t understand how they work. Can anyone have a clear example?

  • They just merge all the files from all the jar'nikov into one. The idea is perilous, because you may lose resource files and meta-content. - Temka also

3 answers 3

Try the assembly plugin:

 <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <archive> <manifest> <mainClass><название класса с методом main></mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> </plugin> </plugins> 

is going to this team mvn clean compile assembly:single

    That's right, you need to connect the plugin. pom.xml add the <build> section to pom.xml , to which you add the <plugins> section, and copy the example from the documentation .

      Try this

       <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.5</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <mainClass>com.example.Start</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <finalName>TestJar</finalName> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.3</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <shadedArtifactAttached>true</shadedArtifactAttached> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer" /> <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> </transformers> </configuration> </execution> </executions> </plugin> </plugins> </build>