idea中用maven打包spring的java项目(非web)

  之前一直用安装的maven打包spring的javaweb项目,用的是mvn assembly:assembly打包,这次打包非web的spring项目,遇到许多问题,特记录一下正确步骤。

1.配置pom.xml

  这里不用assembly,因为assembly在打包时只会把第一次遇到的文件打入jar包,后面遇到的都会skip掉。也就是说assembly把我的Spring描述文件都忽略掉咯。报错就是:找不到 spring-context.xml (我的配置spring的xml),所以这里用 maven-shade-plugin

 1   <build>
 2         <plugins>
 3             <plugin>
 4                 <groupId>org.apache.maven.plugins</groupId>
 5                 <artifactId>maven-shade-plugin</artifactId>
 6                 <version>1.4</version>
 7                 <executions>
 8                     <execution>
 9                         <phase>package</phase>
10                         <goals>
11                             <goal>shade</goal>
12                         </goals>
13                         <configuration>
14                             <transformers>
15                                 <transformer
16                                         implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
17                                     <mainClass>com.peak.App</mainClass>
18                                 </transformer>
19                                 <transformer
20                                         implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
21                                     <resource>META-INF/spring.handlers</resource>
22                                 </transformer>
23                                 <transformer
24                                         implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
25                                     <resource>META-INF/spring.schemas</resource>
26                                 </transformer>
27                                 <transformer
28                                         implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
29                                     <resource>META-INF/spring.tooling</resource>
30                                 </transformer>
31                             </transformers>
32                         </configuration>
33                     </execution>
34                 </executions>
35             </plugin>
36         </plugins>
37     </build>

2.idea中配置

  因为idea集成了maven,所以这里不用特意安装maven

    

  

  

  

3.clean and package (双击运行)

    

 

posted @ 2017-06-13 10:46  peak-c  阅读(2037)  评论(0编辑  收藏  举报