maven 生成可运行的jar

时间:2022-07-08 09:37:51

出自 http://blog.csdn.net/chujiujiao/article/details/8913952

1. 在pom.xml加入如下插件

[html] view plain copy
  1.   <build>    
  2.   <plugins>    
  3.     <plugin>    
  4.       <artifactId>maven-assembly-plugin</artifactId>    
  5.       <configuration>    
  6.         <descriptorRefs>    
  7.           <descriptorRef>jar-with-dependencies</descriptorRef>    
  8.         </descriptorRefs>   
  9.         <archive>    
  10.           <manifest>    
  11.             <mainClass>com.funny_square_webapp.App</mainClass>    
  12.           </manifest>    
  13.         </archive>             
  14.       </configuration>    
  15.     </plugin>    
  16.   </plugins>    
  17. </build>   

2. 运行  mvn assembly:assembly 

3. 在命令行中运行如下命令 

[html] view plain copy
  1. D:\work_project\eclipse_workspace\FunnySquareWebapp\target>java -jar FunnySquare  
  2. Webapp-1.0.1-jar-with-dependencies.jar