本文主要是介绍maven设置打jar包并引入依赖包,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
http://www.cnblogs.com/sheeva/p/5032706.html
--------------------------------------------------------方法一:将jar包和项目打在一起---------------------------------
1.修改pom根节点下packaging属性为jar
2.修改pom根节点下build为:
<build><plugins><plugin><artifactId>maven-assembly-plugin</artifactId><configuration><descriptorRefs><descriptorRef>jar-with-dependencies</descriptorRef></descriptorRefs><archive><manifest><mainClass>com.hbase2Redis.Hbase2Redis</mainClass></manifest></archive></configuration><executions><execution><id>make-assembly</id><phase>package</phase><goals><goal>single</goal></goals></execution></executions></plugin></plugins></build>
3.使用maven install 打包,将在target下生成项目jar包xxx-with-dependencies.jar复制出来,执行java -jar xxx-with-dependencies.jar即可运行。
--------------------------------------------------------方法二:将jar包和项目分离---------------------------------------
1.修改pom根节点下packaging属性为jar
2.修改pom根节点下build为:
<build><finalName>Hbase2Redis</finalName><pluginManagement><plugins><plugin><groupId>org.eclipse.m2e</groupId><artifactId>lifecycle-mapping</artifactId><version>1.0.0</version><configuration><lifecycleMappingMetadata><pluginExecutions><pluginExecution><pluginExecutionFilter><groupId>org.apache.maven.plugins</groupId><artifactId>maven-dependency-plugin</artifactId><versionRange>[2.0,)</versionRange><goals><goal>copy-dependencies</goal></goals></pluginExecutionFilter><action><ignore /></action></pluginExecution></pluginExecutions></lifecycleMappingMetadata></configuration></plugin></plugins></pluginManagement><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><version>2.4</version><configuration><archive><manifest><addClasspath>true</addClasspath><classpathPrefix>lib/</classpathPrefix><!-- 主方法所在类名 --><mainClass>com.hbase2Redis.Hbase2Redis</mainClass></manifest></archive></configuration></plugin><!-- 将依赖包放到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></plugins></build>
3.使用maven install 打包,将在target下生成项目jar包xxx.jar及lib文件夹,将这两者放在同一目录下,执行java -jar xxx.jar即可运行。
http://songpo-ath-taobao-com.iteye.com/blog/2018341
在pom.xml中加入如下配置即可,关键是configuration-descriptorRefs-descriptorRef,这个就表示要将依赖打入jar包。
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <configuration>
- <descriptorRefs>
- <descriptorRef>jar-with-dependencies</descriptorRef>
- </descriptorRefs>
- <archive>
- <manifest>
- <mainClass></mainClass>
- </manifest>
- </archive>
- </configuration>
- <executions>
- <execution>
- <id>make-assembly</id>
- <phase>package</phase>
- <goals>
- <goal>single</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
这篇关于maven设置打jar包并引入依赖包的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!