Dependencies:
- maven-jar-plugin - to create the jar
- maven-assembly-plugin - to get together the distribution package
pom.xml
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <configuration> <archive> <manifest> <mainClass>com.broodcamp.App</mainClass> <addClasspath>true</addClasspath> <classpathPrefix>lib/</classpathPrefix> </manifest> </archive> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptors> <descriptor>${basedir}/src/main/resources/assembly.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin>
What nosotros accept inwards the code:
- In the jounce plugin nosotros define the psyche course of pedagogy as well as laid the classpath to lib.
- We provide a descriptor on how nosotros desire to get together the distribution package. We too bind the plugin to maven's bundle stage as well as unmarried goal. So that nosotros we execute maven install, the bundle volition endure automatically generated.
assembly.xml file
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd"> <id>MyApp Scraper</id> <formats> <format>zip</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <fileSets> <fileSet> <filtered>true</filtered> <directory>src/main/resources</directory> <outputDirectory>./</outputDirectory> <excludes> <exclude>assembly.xml</exclude> </excludes> </fileSet> <fileSet> <directory>${project.build.directory}</directory> <outputDirectory>./</outputDirectory> <includes> <include>*.jar</include> </includes> </fileSet> </fileSets> <dependencySets> <dependencySet> <outputDirectory>/lib</outputDirectory> <unpack>false</unpack> <useTransitiveDependencies>true</useTransitiveDependencies> <includes> <include>*</include> </includes> </dependencySet> </dependencySets> </assembly>
assembly is an xml file where nosotros define how nosotros desire to bundle our distribution. What nosotros have:
- format of the bundle is zip
- We bundle all the resources within src/main/resources folder excluding assembly.xml
- We include all the jounce files inwards the ${project.build.directory} folder which is basically the target.
- We salvage the maven dependencies inwards the lib folder. Note that nosotros laid the course of pedagogy path to the same directory. We laid transitive dependencies to truthful as well as includes all. For unopen to reason, without include=*, unopen to transitive dependencies are non included.
0 komentar:
Please comment if there are any that need to be asked.