自己去看原版:http://www.mkyong.com/maven/create-a-fat-jar-file-maven-assembly-plugin/

一个Eclipse的工程,在pom中配置了若干依赖,需要将pom中所有的依赖全部打包进一个jar包中,可以选择的方案有maven-assembly-plugin和fatjar。以前采用fatjar进行打包,但是fatjar有不少问题,

1. 最近一次更新是在09年,无法支持新版本的eclipse。

2.支持最高的jdk版本是1.7

3. 打包速度慢(不是一般的慢)

4. 打成的jar包体积略大。

下面是一个Eclipse的工程,其中含有不少的maven依赖包:

采用export成runnable jar包的方式是行不通的,正确做法是在工程的pom.xml文件中配置maven-assembly-plugin,pom.xml的配置如下:

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

    <groupId>com.tomas</groupId>    <artifactId>weather</artifactId>    <version>1.0</version>

    <repositories>        <repository>            <id>sonatype-nexus-staging</id>            <name>Sonatype Nexus Staging</name>            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>            <releases>                <enabled>true</enabled>            </releases>            <snapshots>                <enabled>true</enabled>            </snapshots>        </repository>    </repositories>

   <dependencies>        <dependency>            <groupId>com.aliyun</groupId>            <artifactId>aliyun-java-sdk-core</artifactId>            <version>2.4.2</version>        </dependency>        <dependency>            <groupId>com.aliyun</groupId>            <artifactId>aliyun-java-sdk-sms</artifactId>            <version>3.0.0-rc1</version>        </dependency>       <dependency>           <groupId>com.alibaba</groupId>           <artifactId>fastjson</artifactId>           <version>1.2.6</version>       </dependency>       <dependency>           <groupId>org.apache.httpcomponents</groupId>           <artifactId>httpclient</artifactId>          <version>4.5</version>       </dependency>   </dependencies>

    <build>        <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>                </configuration>            </plugin>             <!-- 打包为可执行胖jar -->

            <plugin>                <artifactId>maven-assembly-plugin</artifactId>                <version>2.2.1</version>                <configuration>                    <descriptorRefs>                        <descriptorRef>jar-with-dependencies</descriptorRef>                    </descriptorRefs>                    <archive>                        <manifest>                            <mainClass>com.tomas.waether.SendMessage</mainClass>                        </manifest>                    </archive>                </configuration>            </plugin>        </plugins>    </build>

</project>

Maven 打胖jar的更多相关文章

  1. Maven工程引入jar包

    Maven项目引入jar包的方法 法一.手动导入:项目右键—>Build Path—>Configure Build Path—>选中Libraries—>点击Add Exte ...

  2. maven加载jar包配置

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

  3. maven本地安装jar包同时生成pom文件

    maven 本地安装jar包:mvn install:install-file -Dfile=本地路径/ojdbc12.jar -DgroupId=com.oracle -DartifactId=oj ...

  4. 如何在maven中添加jar包

    Maven 中央仓库地址: 1. http://www.sonatype.org/nexus/ 2. http://mvnrepository.com/ (本人推荐仓库) 3. http://repo ...

  5. 解决Maven关于本地jar包的打包处理

    在使用maven进行jar包管理时,通过我们都是通过maven去下载一些jar包,但有些jar在maven上没有,所以就就可能在本地直接手动加入一些需要用到的外部jar包.但如果我们用maven pa ...

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

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

  7. maven安装 maven上传jar包到库里面

    maven的安装与配置:http://pansanday.blog.163.com/blog/static/381662802012727103454743/ maven上传jar包到库里面: 将私有 ...

  8. Maven工程引入jar包(转)

    Maven项目引入jar包的方法,希望能帮助有需要的朋友们 法一.手动导入:项目右键—>Build Path—>Configure Build Path—>选中Libraries—& ...

  9. 使用Maven管理依赖JAR文件,自定义项目布局,利用ANT生成不同的发布包

    <?xml version="1.0" encoding="GB2312"?> <project name="CardInfo-We ...

随机推荐

  1. 中文翻译:pjsip教程(二)之ICE穿越打洞:Interactive Connectivity Establishment简介

    1:pjsip教程(一)之PJNATH简介 2:pjsip教程(二)之ICE穿越打洞:Interactive Connectivity Establishment简介 3:pjsip教程(三)之ICE ...

  2. C/C++之Exercise

    一.C/C++之初学Demo---C++调用C.h文件使用实例: 工程结构: exercise.h code: #ifndef _EXERCISE_H_ #define _EXERCISE_H_ #i ...

  3. 安装ImageMagick扩展出现configure: error: not found. Please provide a path to MagickWand-config or Wand- config program

    安装ImageMagick扩展报错: checking ImageMagick MagickWand API configuration program... checking Testing /u ...

  4. node 后台ajax文件(同时支持http、https)

    var http = require("http"), Url = require("url"), querystring = require('queryst ...

  5. 编译u-boot命令和u-boot常用命令

    一.编译u-boot命令 1.配置开发板 #make TQ2440_config 2.编译 #make all 3.交叉编译器是crosstools_3.4.5_softfloat” 使用4.3.3版 ...

  6. SQL语句の循环添加数据

    declare @i intset @i=1while @i<=1000begininsert into News_ITM(title,msg,subDateTime,author,imageP ...

  7. Chain of Responsibility

    比较经典的距离是请假申请(<大话设计模式>中的例子),请假是要逐级判断,只有级别到了才有权利审批,从构造上面其实"装饰"模式和"职责链"之间有相通的 ...

  8. tomcat发布静态网页

  9. MVC架构学习

    作为一名小小的GreenBird,学习MVC呢,已经花费了2天了,期间得到了美丽的学姐的帮助,初步整理了一下. 首先,学习MVC呢就先以一个标准的MVC的简单的例子来入手,然后根据学姐的PPT,我用v ...

  10. the design of everyday things

    Design principles: Conceptual models Feedback Constraints Affordances All are important. This is wha ...