<!-- 第一种打包方式 (maven-jar-plugin), 将依赖包和配置文件放到jar包外 -->
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<!-- 将<directory>目录下的文件打包到<targetPath>下 -->
<targetPath>${project.build.directory}</targetPath>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources> <testSourceDirectory>src/test/java</testSourceDirectory>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources> <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin> <!-- 将项目依赖包复制到<outputDirectory>指定的目录下 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin> <!-- 将项目依赖包的路径(与上一项中的<outputDirectory>对应)添加到classPath中 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.ctbri.echoRisk.ApplicationStart</mainClass>
</manifest>
<manifestEntries>
<Class-Path>./</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<!-- 第二种打包方式 (maven-shade-plugin), 将依赖包和配置文件放到jar包内 -->
<build>
<directory>${project.basedir}/target</directory>
<finalName>${project.artifactId}-${project.version}</finalName> <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<extdirs>${project.basedir}/lib/</extdirs>
</compilerArguments>
</configuration>
</plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
<filters>
<filter>
<artifact>*:*</artifact>
</filter>
</filters>
<transformers>
<!-- 往MANIFEST文件中写入Main-Class是可执行包的必要条件。ManifestResourceTransformer可以轻松实现。 -->
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.ctbri.echoRisk.ApplicationStart</mainClass>
</transformer>
<!-- AppendingTransformer 用来处理多个jar包中存在重名的配置文件的合并,尤其是spring -->
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- 第三种打包方式 (maven-assembly-plugin) -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin> <plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<extdirs>${project.basedir}/lib/</extdirs>
</compilerArguments>
</configuration>
</plugin> <plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.ctbri.echoRisk.ApplicationStart</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Maven项目导出jar包配置的更多相关文章

  1. Maven项目导出jar包,包含依赖

    1. Maven项目导出jar包,包含依赖:mvn dependency:copy-dependencies package 2. 可以在Project创建lib文件夹,输入以下命令:mvn depe ...

  2. IDEA中MAVEN项目打JAR包的简单方法

      Idea中为一般的非Web项目打Jar包是有自己的方法的,网上一搜就能查到很多. 但是如果是为Maven项目打Jar包,其实是很简单的,因为maven本身就有打Jar包的命令.   最简单的方法 ...

  3. Eclipse中将项目导出jar包,以及转化成exe的方法

    Eclipse中将项目导出jar包,以及转化成exe的方法 http://wenku.baidu.com/view/385597f07c1cfad6195fa7c6.html

  4. idea中maven项目打jar包

    从Eclipse换成Idea的小伙伴们可能会找不到Eclipse中Maven项目打jar包的方法,因为eclipse只需要在工程上点击右键,右键菜单中就有Maven打包的相关选项. 然而Idea的右键 ...

  5. Maven项目聚合 jar包锁定 依赖传递 私服

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  6. maven加载jar包配置

    maven build时报程序包不存在和找不到符号的错误,但是代码中不报错,如下: [ERROR] Failed to execute goal org.apache.maven.plugins:ma ...

  7. 转:maven项目添加jar包.

    很多新手都不知道如何在maven项目里添加jar包. 以前我还没接触maven的时候下载过一个demo,是maven项目. 我居然是照着他的pom.xml文件一个一个的写!!! 很多人认为理所当然的东 ...

  8. MyEclipse中将项目导出jar包,以及转化成EXE文件

    1.对于项目如何导出jar文件,和生成exe,解答目录如下: 首先生成jar文件,单击项目名称CF-users(这是我的协同过滤项目文件名称)右击--->Export如下图: 单击下一步 Sel ...

  9. 关于使用命令添加jar进自己的pom文件中-maven项目添加jar包

    现在几乎开发项目都是使用的maven项目,但是有的时候可以使用比较偏门或者新的jar可能在网上搜不到在pom文件里的配置应该如何写,因此写下这篇博客. 比如我现在想加入的AAA.jar这个包 打开cm ...

随机推荐

  1. ubuntu16.04+cuda8.0+caffe

    =========== 如果出现nvidia-smi failed to communicate with nvidia driver,循环登录情况,则: sudo apt-get remove -- ...

  2. 手机访问本地php项目遇到的问题及解决

    做html5的本地应用要调试后台,学了下php 按照和连j2ee的时候一样,电脑发射wifi,ipconfig..等等  发现tomcat的可以访问,apache的不能访问,搜索好久,没找到解答, j ...

  3. Internet History, Technology and Security (Week3)

    Week3. Welcome to week 3! This is our fourth and final week of History where we make the connection ...

  4. Alpha 冲刺报告(4/10)

    Alpha 冲刺报告(4/10) 队名:洛基小队 峻雄(组长) 已完成:继续行动脚本的编写 明日计划:尽量完成角色的移动 剩余任务:物品背包交互代码 困难:具体编码进展比较缓慢 ----------- ...

  5. Internet History, Technology and Security (Week 4)

    Week 4 History: Commercialization and Growth We are now moving into Week 4! This week, we will be co ...

  6. 个人作业-week3案例分析

    第一部分 软件调研测评(必应词典移动端) 找到的bug: 在词汇量测试中每个单词给用户思考的时间太短,只有五秒钟.导致很多似曾相识的单词还没来得及想起就已经过了.如果说测的是用户记忆深刻的单词,那些记 ...

  7. CMD命令去导出文件下的文件名称到EXCEL

      dir C:\Users\caire\Pictures\壁纸/b>E:\temp.xls

  8. poj 3254(状态压缩DP)

    poj  3254(状态压缩DP) 题意:一个矩阵里有很多格子,每个格子有两种状态,可以放牧和不可以放牧,可以放牧用1表示,否则用0表示,在这块牧场放牛,要求两个相邻的方格不能同时放牛,即牛与牛不能相 ...

  9. Jquery插件收集【m了慢慢学】

    1. Simple Effects for Drop-Down Lists 一个jQuery插件用于将普通的select控件转成一个带有一些简单扩展效果的下拉列表. 2. X-editable 这个插 ...

  10. Hibernate 注解之 @Temporal

    因为数据库中有个 Date类型的数据,在从数据库中获取数据[就是getXxx方法,当然,自动装配的时候可以直接写在字段上,但也只是针对getXxx方法,不会自动赋值]的时候可以利用这个 @Tempor ...