首页 > 代码库 > maven插件介绍之maven-jar-plugin

maven插件介绍之maven-jar-plugin

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