自己去看原版: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. MySQL全文检索笔记 转载

    1. MySQL 4.x版本及以上版本提供了全文检索支持,但是表的存储引擎类型必须为MyISAM,以下是建表SQL,注意其中显式设置了存储引擎类型 CREATE TABLE articles ( id ...

  2. eclipse/ggts/myeclipse清除SVN用户名和密码

    很多时候我们在使用eclipse/myeclipse/ggts这些开发工具进行开发的时候会有多个项目存在,不同的项目又存放在不同的svn下,需要进行svn之间的切换,如果你在创建资源库位置的时候保存了 ...

  3. yii2源码学习笔记(十六)

    Module类的最后代码 /** * Registers sub-modules in the current module. * 注册子模块到当前模块 * Each sub-module shoul ...

  4. JQuery 字符串截取

    //字符串截取,全小写 strObj.substring(startIndex,endIndex); //需要注意大小写 strObj.lastIndexOf(String splitObj); // ...

  5. 图片延迟加载插件jquery.lazyload.js的使用方法

    最新版的jquery.lazyload.js已不再是伪的延迟加载了 一.请按照基本使用方法说明设置 //载入JavaScript 文件 <script src="jquery.js&q ...

  6. Python疑问系列

    最近在看python源码 ------点点滴滴做个记录. 预计要分的系列: 1. import 分析 2. 主要bytecode 分析 3. python启动分析 4. object对象分析 最后希望 ...

  7. 面向对象js瀑布流效果

    index.html <!doctype html><html lang="en"> <head>  <!--网站编码格式,UTF-8 国 ...

  8. python关键字

    python有多少关键字? >>> import keyword >>> keyword.kwlist ['and', 'as', 'assert', 'break ...

  9. bzoj 2152: 聪聪可可 树的点分治

    2152: 聪聪可可 Time Limit: 3 Sec  Memory Limit: 259 MBSubmit: 485  Solved: 251[Submit][Status] Descripti ...

  10. ZOOKEEPER在CENTOS6上的再安装

    作DUBBO时,肯定是需要的,,对的,,DUBBO也要熟悉一下才行啦.. URL: http://www.centoscn.com/CentosServer/test/2015/0120/4531.h ...