maven 插件用法

maven的核心部件很小,主要功能都是通过插件来完成了。最近用到几种插件,记录下。

1)ant插件,起因是用到kettle代码,但是kettle用ant管理的,彻底改造会非常麻烦,所以用到了ant插件。在maven的package阶段调用,指定了ant的build.xml文件的位置,执行的是ant dist

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-antrun-plugin</artifactId>
	<version>1.8</version>
	<executions>
		<execution>
			<id>package</id>
			<phase>package</phase>
			<configuration>
				<target unless="skip.engine">
					<ant antfile="${basedir}/build.xml">
						<target name="dist" />
					</ant>
				</target>
			</configuration>
			<goals>
				<goal>run</goal>
			</goals>
		</execution>
	</executions>
</plugin>

2)clean插件,起因是开始的思路是仍用ant插件,在clean阶段调用ant clean即可。

但是第一:maven会有自己的target目录,ant clean不能删除;

       第二:maven里如果有本地的依赖的话,ant clean还会提示依赖出错,这个没想明白为什么clean还检查依赖性。。。

网上找了半天没有解决,决定用clean插件,粗暴删除指定的目录了!!

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-clean-plugin</artifactId>
	<version>2.5</version>
	<configuration>
		<filesets>
			<fileset>
				<directory>${project.basedir}/dist</directory>
			</fileset>
			<fileset>
				<directory>${project.basedir}/bin</directory>
			</fileset>
		</filesets>
	</configuration>
</plugin>

target目录maven本身默认就会删除,这里就不用指定了。指定下ant编译生成的目录即可。


3)install插件。起因还是ant插件,ant生成的jar包,名称和位置都maven都不认识,maven install不是闹着玩么。。要将编译出来的jar安装到maven的本地仓库还得用插件。

<plugin>  
    <groupId>org.apache.maven.plugins</groupId>  
    <artifactId>maven-install-plugin</artifactId>  
    <version>2.3.1</version>  
    <executions>  
        <execution>  
            <id>Install kettle engine</id>  
            <phase>install</phase>  
            <goals>  
                <goal>install-file</goal>  
            </goals>  
            <configuration>  
                <packaging>jar</packaging>  
                <groupId>kettle-engine</groupId>  
                <artifactId>kettle-engine</artifactId>  
                <version>${version}</version>  
                <file>${basedir}/dist/kettle-engine-5.3-SNAPSHOT.jar</file>  
            </configuration>  
        </execution>  
    </executions>  
</plugin> 

这里的groupId和artifactId坐标可以随便指定,file指定要安装的jar包来源。安装好之后其他的模块就可以开心地用这个依赖了。


4)还有一个插件是在刚开始学习maven的时候用到的,指定main class,这样打包出来的jar包就可以直接用java -jar xx.jar运行了。

<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>
                <transformers>
                    <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>com.dtdream.dxt.App</mainClass>
                    </transformer>
                </transformers>
            </configuration>
        </execution>
    </executions>
</plugin>




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值