1. 程式人生 > >關於maven 把插件依賴一起打包進jar問題

關於maven 把插件依賴一起打包進jar問題

java hdfs 自己的 編譯過程 location schema ase 網上 dir

今天在做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如果不使用要刪掉的問題等等,大多網上很容易找到答案就不一一記錄了,還要註意自己的項目路徑,編譯過程不知道為什麽有一次被自己換了路徑,還原回來就好了)

技術分享

關於maven 把插件依賴一起打包進jar問題