maven 3 jar 运行文件打包

14 篇文章 0 订阅

1. maven 主要文件pom.xml 这就不用多说了

 

因为我们要打包*.jar 运行文件

 

 

Xml代码
  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  2.   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  3.     <modelVersion>4.0.0</modelVersion>  
  4.   
  5.     <groupId>com.helloworld</groupId>  
  6.     <artifactId>usbHelloworld</artifactId>  
  7.     <version>1.0-SNAPSHOT</version>  
  8.     <packaging>jar</packaging>  
  9.   
  10.     <name>usb</name>  
  11.     <url>http://maven.apache.org</url>  
  12.   
  13.     <properties>  
  14.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
  15.     </properties>  
  16.   
  17.     <dependencies>  
  18.         <dependency>  
  19.             <groupId>junit</groupId>  
  20.             <artifactId>junit</artifactId>  
  21.             <version>4.7</version>  
  22.             <scope>test</scope>  
  23.         </dependency>  
  24.     </dependencies>  
  25.     <build>  
  26.         <plugins>  
  27.             <plugin>  
  28.                    
  29.                 <groupId>org.apache.maven.plugins</groupId>  
  30.                     <!--加入对应的插件内容-->  
  31.                     <artifactId>maven-shade-plugin</artifactId>  
  32.                     <configuration>  
  33.                         <source>1.6</source>  
  34.                         <target>1.6</target>  
  35.                     </configuration>  
  36.                     <executions>  
  37.                         <execution>  
  38.                             <phase>package</phase>  
  39.                             <goals>  
  40.                                 <goal>shade</goal>  
  41.                             </goals>  
  42.                             <configuration>  
  43.                                 <transformers>  
  44.                                     <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">  
  45.                                         <mainClass>com.helloworld.HelloWorld</mainClass>  
  46.                                     </transformer>  
  47.                                 </transformers>  
  48.                             </configuration>  
  49.                         </execution>  
  50.                     </executions>  
  51.             </plugin>  
  52.         </plugins>  
  53.     </build>  
  54. </project>  

 

 

 

 

Java代码
  1. E:\mavenTest\workspace\helloWorld>mvn clean install   
  2. [INFO] Scanning for projects...   
  3. [WARNING]   
  4. [WARNING] Some problems were encountered while building the e   
  5. com.helloworld:usbHelloworld:jar:1.0-SNAPSHOT   
  6. [WARNING] 'build.plugins.plugin.version' for org.apache.maven   
  7. e-plugin is missing. @ line 28, column 15  
  8. [WARNING]   
  9. [WARNING] It is highly recommended to fix these problems beca   
  10. he stability of your build.   
  11. [WARNING]  
E:\mavenTest\workspace\helloWorld>mvn clean install
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the e
com.helloworld:usbHelloworld:jar:1.0-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven
e-plugin is missing. @ line 28, column 15
[WARNING]
[WARNING] It is highly recommended to fix these problems beca
he stability of your build.
[WARNING]

 

 

Java代码
  1. [INFO] Installing E:\mavenTest\workspace\helloWorld\target\   
  2. PSHOT.jar to C:\Documents and Settings\Administrator\.m2\re   
  3. ld\usbHelloworld\1.0-SNAPSHOT\usbHelloworld-1.0-SNAPSHOT.ja   
  4. [INFO] Installing E:\mavenTest\workspace\helloWorld\pom.xml   
  5. Settings\Administrator\.m2\repository\com\helloworld\usbHel   
  6. usbHelloworld-1.0-SNAPSHOT.pom   
  7. [INFO] ----------------------------------------------------   
  8. [INFO] BUILD SUCCESS   
  9. [INFO] ----------------------------------------------------   
  10. [INFO] Total time: 2.297s   
  11. [INFO] Finished at: Mon Dec 26 22:54:45 CST 2011  
  12. [INFO] Final Memory: 6M/16M   
  13. [INFO] ----------------------------------------------------   
  14. E:\mavenTest\workspace\helloWorld>  
[INFO] Installing E:\mavenTest\workspace\helloWorld\target\
PSHOT.jar to C:\Documents and Settings\Administrator\.m2\re
ld\usbHelloworld\1.0-SNAPSHOT\usbHelloworld-1.0-SNAPSHOT.ja
[INFO] Installing E:\mavenTest\workspace\helloWorld\pom.xml
Settings\Administrator\.m2\repository\com\helloworld\usbHel
usbHelloworld-1.0-SNAPSHOT.pom
[INFO] ----------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ----------------------------------------------------
[INFO] Total time: 2.297s
[INFO] Finished at: Mon Dec 26 22:54:45 CST 2011
[INFO] Final Memory: 6M/16M
[INFO] ----------------------------------------------------
E:\mavenTest\workspace\helloWorld>
 

 

OK 运行成功

 

 

Java代码
  1. E:\mavenTest\workspace\helloWorld\target>java -jar usbHelloworld-1.0-SNAPSHOT-sh   
  2. aded.jar   
  3. Hello World!  
E:\mavenTest\workspace\helloWorld\target>java -jar usbHelloworld-1.0-SNAPSHOT-sh
aded.jar
Hello World!

 

文件路径

 

projectName \src\main\java\com\zk\HelloWorld.java

                    \pom.xml

 

 

 

META-INF/MANIFEST.MF 文件内容

 

 

Java代码
  1. Manifest-Version: 1.0  
  2. Build-Jdk: 1.6.0_29   
  3. Built-By: liuqing   
  4. Created-By: Apache Maven   
  5. Main-Class: com.helloworld.HelloWorld   
  6. Archiver-Version: Plexus Archiver  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值