1. 程式人生 > >maven插件介紹之maven-jar-plugin

maven插件介紹之maven-jar-plugin

content letter post end version class pid 技術交流 cut

maven-jar-plugin 插件的maven依賴為:

<dependency>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.6</version>
</dependency>


一: 打包可運行的jar

配置為:

<build>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-jar-plugin</artifactId>
			<version>2.6</version>
			<configuration>
				<archive>
					<manifest>
						<addClasspath>true</addClasspath>
						<classpathPrefix>lib/</classpathPrefix>
						<mainClass>com.lala.shop.App</mainClass>
					</manifest>
				</archive>
			</configuration>
		</plugin>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-dependency-plugin</artifactId>
			<version>2.10</version>
			<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>
	</plugins>
</build>

假設項目有依賴其他的jar,就須要maven-dependency-plugin插件把其他依賴也一起打包,否則。就不須要


二: 打包部分package

比方說。我僅僅想打包com.lala.api*以下的類打包。則配置例如以下

<build>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-jar-plugin</artifactId>
			<version>2.6</version>
			<configuration>
				<includes>
					<include>**/api/*</include>
				</includes>
			</configuration>
		</plugin>
	</plugins>
</build>



maven技術交流 扣扣群 379165311,群裏面會不定期分享一些maven文章和教程,歡迎大家增加

maven插件介紹之maven-jar-plugin