您的位置:首页 > 其它

关于maven 把插件依赖一起打包进jar问题

2017-07-29 11:21 489 查看
今天在做storm on maven的时候发现要依赖到storm-hdfs的jar。自己又非常不想把乱七八糟的东西丢上自己的集群lib。于是就想maven 打包的时候把插件一块打包进jar。maven默认自己不会打包进jar,我只要把自己需要的打包进去就好了。

走了不少弯路,现在记录一把,防止以后自己用到:

我的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>storm.lesson</groupId>
<artifactId>storm.lesson</artifactId>
<version>0.0.1</version>
<dependencies>
<dependency>
<groupId>org.apache.storm</groupId>
<artifactId>storm-core</artifactId>
<version>0.10.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.storm</groupId>
<artifactId>storm-hdfs</artifactId>
<version>0.10.0</version>
<scope>compile</scope><!--需要打包进去的插件必须是编译级别-->
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>

<!--以下是要做进去的插件包-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>org.apache.storm:storm-hdfs</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>
</project>

打包完成后会发现依赖包的class会被一起被打进生intall jar包。(过程要注意的点有jdk jre级别问题,默认的m2如果不使用要删掉的问题等等,大多网上很容易找到答案就不一一记录了,还要注意自己的项目路径,编译过程不知道为什么有一次被自己换了路径,还原回来就好了)

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: