转自:http://blog.csdn.net/johnnywww/article/details/7964326

1.修改pom.xml增加如下内容

            <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.sysware.HelloWorld</mainClass>
</manifest>
</archive>
</configuration>
</plugin>

运行mvn clean package即可

2.在pom.xml增加如下内容

            <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.juvenxu.mvnbook.helloworld.HelloWorld</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
</plugin>

运行mvn assembly:assembly

3.

<build>
<finalName>...</finalName>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<!-- 控制资源文件的拷贝 -->
<resource>
<directory>src/main/resources</directory>
<targetPath>${project.build.directory}</targetPath>
</resource>
</resources>
<plugins>
<!-- 设置源文件编码方式 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-</encoding>
</configuration>
</plugin>
<!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>.....MonitorMain</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<!-- 拷贝依赖的jar包到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>
<!-- 解决资源文件的编码问题 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.3</version>
<configuration>
<encoding>UTF-</encoding>
</configuration>
</plugin>
<!-- 打包source文件为jar文件 -->
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.1</version>
<configuration>
<attach>true</attach>
<encoding>UTF-</encoding>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

4.

    <build>
<resources>
<resource>
<targetPath>${project.build.directory}/classes</targetPath>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.test.testguava.app.App</mainClass>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>applicationContext.xml</resource>
</transformer>
</transformers>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>executable</shadedClassifierName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

maven 打包可执行jar的方法的更多相关文章

  1. maven打包可执行jar文件运行报错

    起因 项目中同时依赖了Spring和MyBatis,并使用mybatis-spring集成MyBatis和Spring. 使用maven打包为可执行jar文件运行,打包插件为:maven-shade- ...

  2. spring boot项目maven打包可执行JAR

    在pom.xml中添加如下配置: <!-- 打包可执行jar包 --> <plugin> <groupId>org.springframework.boot< ...

  3. Maven打包可执行Jar包方式

    第一步:pom.xm中的build标签下加入maven插件配置,打包生成可执行jar包方式Maven中的打包方式更换为 <packaging>jar</packaging> b ...

  4. Apache Maven 打包可执行jar

    在本文的 参考资料 部分,您将发现大量介绍 Maven 的入门教程.本文的 5 个技巧目的是帮助您解决即将出现的一些问题:使用 Maven 管理您的应用程序的生命周期时,将会出现的编程场景. 1. 可 ...

  5. Spring Boot Maven 打包可执行Jar文件!

    Maven pom.xml 必须包含 <packaging>jar</packaging> <build> <plugins> <plugin&g ...

  6. maven 打包可执行jar的两种方法

    1.修改pom.xml增加如下内容 <build> <pluginManagement> <plugins> <plugin> <groupId& ...

  7. Maven打包可执行Jar的几种方法

    http://m.blog.csdn.net/article/details?id=51871705

  8. Spring Boot Maven 打包可执行Jar文件

    本文转载自:http://blog.csdn.net/smilecall/article/details/56288972 Maven pom.xml 必须包含 <packaging>ja ...

  9. Maven打包可执行jar

    参考文献:http://blog.csdn.net/xiao__gui/article/details/47341385 方法:使用assembly插件,生成的jar包名为xxx-jar-with-d ...

随机推荐

  1. SQLCE使用本地数据库优化

    一.数据绑定 1.使用数据虚拟化和SKIP/TAKE 使用 Skip 和 Take 方法可确保直到需要在 ListBox 控件中显示数据时才将数据库中的数据加载到内存中. 例如,以下代码显示了如何从数 ...

  2. SUSE Linux – Zypper 命令示例

    來源:http://www.linuxidc.com/Linux/2014-11/109214.htm Zypper是SUSE Linux中用于安装,升级,卸载,管理仓库.进行各种包查询的命令行接口. ...

  3. git push.default设置

    转自:http://blog.csdn.net/daijingxin/article/details/51326715 在进行一次空仓库的提交时,我遇到了这个警告 警告如下: warning: pus ...

  4. 黑镜第一至二季/全集Black Mirror迅雷下载

    本季第一.二季 Black Mirror (2011-2013)看点:<黑镜>(Black Mirror)是一部由查理·布洛克主创.英国电视4台(Channel 4)于2011年12月播出 ...

  5. http链接的性能测试工具httping

    安装:MAC环境下使用brew进行安装      brew  install  httping 使用参数: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 1 ...

  6. [Web 前端] Jquery实现可直接编辑的表格

    cp from :https://www.cnblogs.com/sjqq/p/6392001.html?utm_source=itdadao&utm_medium=referral 文实例讲 ...

  7. 第三方IDC性能测评主要指标

    弹性计算性能弹性计费模式就是 "即用即付 ",最小单位可以按小时来计算.随着云计算负载的增长,企业购买服务器带宽时的资源.   1.弹性计算性能   弹性计费模式就是"即 ...

  8. [转]一次非常有意思的sql优化经历

    From :http://www.cnblogs.com/tangyanbo/p/4462734.html 补充:看到这么多朋友对sql优化感兴趣,我又重新补充了下文章的内容,将更多关于sql优化的知 ...

  9. 如何设置浏览器禁止使用UC浏览器

    通过UA可以判断浏览器是否是UC浏览器 if(navigator.userAgent.indexOf('UCBrowser')>-1) {  alert("当前浏览器不支持本站,建议更 ...

  10. django的权限认证:登录和退出。auth模块和@login_required装饰器

    在settings.py中配置LOGIN_URL参数: # 用户访问带有(@login_required)标签的页面(view)时,如果没有登录,就会跳转到LOGIN_URL(即登陆url). LOG ...