Maven打包程序

1、src/main目录下建立scritps、config、assembly目录
scritps:存放脚本文件如批处理
assembly:打包配置文件
 
2、assembly目录下建立package.xml
 <assembly>
<id>bin</id>
<!-- 最终打包成一个用于发布的zip文件 -->
<formats>
<format>zip</format>
</formats> <!-- Adds dependencies to zip package under lib directory -->
<dependencySets>
<dependencySet>
<!-- 第三方jar不要解压,打包进zip文件的lib目录 -->
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
<unpack>false</unpack>
</dependencySet>
</dependencySets> <fileSets>
<!-- 把项目相关的说明文件,打包进zip文件的根目录 -->
<fileSet>
<directory>${project.basedir}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>NOTICE*</include>
</includes>
</fileSet> <!-- 把项目的配置文件,打包进zip文件的config目录 -->
<fileSet>
<directory>${project.basedir}\src\main\resources</directory>
<outputDirectory>conf</outputDirectory>
<includes>
<include>*.properties</include>
</includes>
</fileSet> <!-- 把项目的脚本文件目录中的启动脚本文件,打包进zip文件的跟目录 -->
<fileSet>
<directory>${project.basedir}\src\main\scripts</directory>
<outputDirectory></outputDirectory>
<includes>
<include>run.*</include>
</includes>
</fileSet> <!-- 把项目自己编译出来的jar文件,打包进zip文件的根目录 -->
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory></outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>

3、修改pom.xml文件,增加plugin

   <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
   <archive>
   <manifest>
  <addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>程序main函数所在类的全类名</mainClass>
</manifest>
</archive>
12      </configuration>
  </plugin> <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>.</version>
  <configuration>
21        <descriptors>
  <descriptor>src/main/assembly/package.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
    </execution>
  </executions>
</plugin>
上一篇:JavaScript学习记录一


下一篇:Struts2初始(一)