Chinaunix首页 | 论坛 | 博客
  • 博客访问: 273432
  • 博文数量: 127
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1018
  • 用 户 组: 普通用户
  • 注册时间: 2016-03-11 14:13
  • 认证徽章:
个人简介

狂甩酷拽吊炸天

文章分类

全部博文(127)

文章存档

2019年(25)

2018年(17)

2017年(35)

2016年(50)

分类: Java

2019-08-16 16:14:32

最近在写java,由于之前一直写python,对java知之甚少,也不用maven,今天用maven打jar包,各种坎坷,有打不进去依赖的,有maven报ERROR的,网上的资料零零碎碎,黏贴进pom文件各种报错,下面总结一下我正确的打依赖jar包方式,pom文件如下:


点击(此处)折叠或打开

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3.          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5.     <modelVersion>4.0.0</modelVersion>

  6.     <groupId>com.xxxx</groupId>
  7.     <artifactId>es-core</artifactId>
  8.     <version>1.0-SNAPSHOT</version>
  9.     <packaging>jar</packaging>

  10.     <name>es-core</name>

  11.     <properties>
  12.         <maven.compiler.source>1.8</maven.compiler.source>
  13.         <maven.compiler.target>1.8</maven.compiler.target>
  14.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  15.     </properties>

  16.     <dependencies>
  17.         <dependency>
  18.             <groupId>org.elasticsearch.client</groupId>
  19.             <artifactId>transport</artifactId>
  20.             <version>6.4.2</version>
  21.             <scope>compile</scope>
  22.         </dependency>

  23.         <dependency>
  24.             <groupId>org.elasticsearch.client</groupId>
  25.             <artifactId>elasticsearch-rest-high-level-client</artifactId>
  26.             <version>6.4.2</version>
  27.             <scope>compile</scope>
  28.         </dependency>

  29.         <dependency>
  30.             <groupId>org.apache.logging.log4j</groupId>
  31.             <artifactId>log4j-api</artifactId>
  32.             <version>2.9.1</version>
  33.             <scope>compile</scope>
  34.         </dependency>

  35.         <dependency>
  36.             <groupId>org.apache.logging.log4j</groupId>
  37.             <artifactId>log4j-core</artifactId>
  38.             <version>2.9.1</version>
  39.             <scope>compile</scope>
  40.         </dependency>
  41.     </dependencies>


  42.     <build>
  43.         <plugins>
  44.             <!--情景一,制定程序入口即可。-->
  45.             <!--<plugin>
  46.                 <groupId>org.apache.maven.plugins</groupId>
  47.                 <artifactId>maven-shade-plugin</artifactId>
  48.                 <version>1.2.1</version>
  49.                 <executions>
  50.                     <execution>
  51.                         <phase>package</phase>
  52.                         <goals>
  53.                             <goal>shade</goal>
  54.                         </goals>
  55.                         <configuration>
  56.                             <transformers>
  57.                                 <transformer
  58.                                         implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
  59.                                     <mainClass>com.study.App</mainClass>
  60.                                 </transformer>
  61.                             </transformers>
  62.                         </configuration>
  63.                     </execution>
  64.                 </executions>
  65.             </plugin>-->

  66.             <!--情景二,使打包的jar包含lib文件夹中的本地jar-->
  67.             <plugin>
  68.                 <groupId>org.apache.maven.plugins</groupId>
  69.                 <artifactId>maven-jar-plugin</artifactId>
  70.                 <configuration>
  71.                     <archive>
  72.                         <manifest>
  73.                             <mainClass>com.study.App</mainClass>
  74.                         </manifest>
  75.                     </archive>
  76.                 </configuration>
  77.             </plugin>
  78.             <plugin>
  79.                 <groupId>com.jolira</groupId>
  80.                 <artifactId>onejar-maven-plugin</artifactId>
  81.                 <version>1.4.4</version>
  82.                 <executions>
  83.                     <execution>
  84.                         <configuration>
  85.                             <attachToBuild>true</attachToBuild>
  86.                             <classifier>onejar</classifier>
  87.                         </configuration>
  88.                         <goals>
  89.                             <goal>one-jar</goal>
  90.                         </goals>
  91.                     </execution>
  92.                 </executions>
  93.             </plugin>
  94.         </plugins>
  95.     </build>

  96. </project>
运行package之后,会生成两个jar文件,一个xxxx.jar, 另一个是xxxx.one-jar.jar, 其中xxxx.jar是不含依赖的jar包,xxxx.one-jar.jar是含依赖的jar包, 直接运行含依赖的jar包就行(PS:注意修改其中的<mainClass></mainClass>标签中的内容

阅读(12281) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
请登录后评论。

登录 注册