本文主要總結最近一段時間使用maven時,遇到須要maven plugins的一些簡單總結。apache
<build> <!--最終打包的包名,若是這裏不指定,則默認包名爲:artifactId-version.jar(com-test-project-1.0-SNAPSHOT.jar)--> <finalName>The-Test-Pro</finalName> ... </build>
a)在dependencies下引入lib下的jarmaven
<dependency> <groupId>org.apache.spark</groupId> <artifactId>spark-core_2.11-1.5.2.logging</artifactId> <version>2.11</version> <scope>system</scope> <systemPath>${project.basedir}/lib/spark-core_2.11-1.5.2.logging-2.11.jar</systemPath> </dependency>
b)在maven-compiler-plugin配置包時將/lib下的包打包進來ui
<!--代碼編譯,指定擴展包在lib下,且打包時將/lib下的包打包進來--> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <encoding>UTF-8</encoding> <source>1.8</source> <target>1.8</target> <showWarnings>true</showWarnings> <compilerArguments> <extdirs>${project.basedir}/lib</extdirs> </compilerArguments> </configuration> </plugin>
<!-- 在pom中配置了若干依賴,須要將pom中全部的依賴所有打包進一個jar包中,能夠選擇的方案有maven-assembly-plugin 此時,在Target下會打包一個finalName-jar-with-dependencies.jar,(不指定finalName時:artifactId-version-with-dependencies.jar) --> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <archive> <manifest> <mainClass>com.main.Invoker</mainClass> </manifest> </archive> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin>
<!-- 拷貝依賴的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-dependencies</goal> </goals> <configuration> <outputDirectory> ${project.build.directory}/lib </outputDirectory> </configuration> </execution> </executions> </plugin>