maven插件

来源:互联网 发布:工程进度网络图软件 编辑:程序博客网 时间:2024/05/22 03:44

插件网站:

http://maven.apache.org/plugins/
最好的学习方法是直接上官网看插件文档

maven-assembly-plugin插件
文档地址: http://maven.apache.org/plugins/maven-assembly-plugin/usage.html
参考博文: http://blog.csdn.net/cdl2008sky/article/details/6756177
现在将依赖jar和工程代码打包到一个jar中,暂时使用的是这个方法.
这个插件可以将工程打包成多种形式发布,以下配置的作用是在使用mvn package命令的时候,将工程所有依赖的jar打包进一个jar中.下面的jar-with-dependencies是默认的一种形式,不能写错
<plugin>
<groupId>
org.apache.maven.plugins</groupId>
<artifactId>
maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>
jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>
com.tcl.bigdata.yhb.timer.TimerDependence</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>
make-assembly</id>
<phase>
package</phase>
<goals>
<goal>
single</goal>
</goals>
</execution>
</executions>
</plugin>
生成包含依赖的jar包有一个jar-with-dependencies的后缀.

注意,是pom.xml中scope不为complie的jar是不会被打包进一个jar中的,像以下test范围的就不会打包进一个jar


maven-jar-plugin插件:
以下配置在打包jar的时候,在MANIFEST.MF文件中添加MainClass和ClassPath.如果没有以下配置,maven的默认打包是不添加MainClass的.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>target/lib</classpathPrefix>
<mainClass>com.tcl.bigdata.yhb.timer.TimerDependence</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
结果如下:


maven-dependency-plugin插件:
这个插件可以将依赖jar包导出到任何目录下,例如以下配置将scala-library-2.10.5.jar导出到target/lib
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.10.5</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>target/lib</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>




0 0
原创粉丝点击