maven assembly插件打包工程
作者:互联网
使用maven的assembly插件打包工程至服务器,具体步骤如下:
1.在maven工程的pom.xml文件中加入以下内容:
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptors>
<descriptor>src/assembly/src.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>com.kevin.Kevin</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
2.assembly的配置文件src.xml内容如下:
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>Kevin</id>
<formats>
<format>tar.gz</format>
</formats>
<fileSets>
<fileSet>
<directory>target</directory>
<outputDirectory>/lib</outputDirectory>
<includes>
<include>spark_test-0.0.1-SNAPSHOT.jar</include>
</includes>
<fileMode>544</fileMode>
</fileSet>
<fileSet>
<directory>target/classes</directory>
<outputDirectory>/conf</outputDirectory>
<includes>
<include>*.xml</include>
</includes>
<fileMode>544</fileMode>
</fileSet>
<fileSet>
<directory>target/classes</directory>
<outputDirectory>/conf</outputDirectory>
<includes>
<include>*.xml</include>
</includes>
<fileMode>544</fileMode>
</fileSet>
<fileSet>
<directory>target/classes/assembly</directory>
<outputDirectory>/bin</outputDirectory>
<includes>
<include>start.sh</include>
</includes>
<fileMode>544</fileMode>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<fileMode>544</fileMode>
</dependencySet>
</dependencySets>
</assembly>
附:
启动工程的shell脚本(start.sh):
#!/bin/sh
#start the dubbo service
java -Djava.ext.dirs=../lib -classpath ../lib/spark_test-0.0.1-SNAPSHOT.jar com.kevin.Kevin
第二次打包方式: 如果使用已有的插件Predefined descriptors进行打包,用以下方式比较方便:
在pom.xml文件中的<build>节点中加入以下内容,并在maven工具中的Lifecycle中执行"package"节点,即可打成可执行包。
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.kevin.consumer.ConsumerApplication</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
标签:xml,插件,assembly,maven,544,org,http 来源: https://www.cnblogs.com/guaixia/p/14003852.html