maven生成可执行jar包题总结

来源:互联网 发布:位图转换为矢量图软件 编辑:程序博客网 时间:2024/05/16 04:38
(1)依赖jar包未打入到同一个jar文件中可以通过使用maven-shade-plugin插件解决这个问题。
 <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResource                                       Transformer">
                   <!-- 程序入口类 -->
                   <mainClass>com.xxxx.xxx.ServerStartup</mainClass>
                </transformer>
                            <transformer  
                                implementation="org.apache.maven.plugins.shade.resource.AppendingTran                                                                  sformer">  
                                <resource>META-INF/spring.handlers</resource>  
                            </transformer>  
                            <transformer  
                                implementation="org.apache.maven.plugins.shade.resource.AppendingTran                                                                              sformer">  
                                <resource>META-INF/spring.schemas</resource>  
                            </transformer>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin>
(2) 再打jar包过程中出现了java代码对jdk的版本有要求时,可以采用以下配置方式,对jdk的版本进行配置。
<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <encoding>UTF-8</encoding>
                </configuration>
     </plugin>
(3)将java代码所涉及到资源文件(如dao层下面的xml统一打入jar包中),可以采用如下插件。
 <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.4</version>
            <executions>
                <execution>
                    <id>copy-xmls</id>
                    <phase>process-sources</phase>
                    <goals>
                        <goal>copy-resources</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${basedir}/target/classes</outputDirectory>
                        <resources>
                            <resource>
                                <directory>${basedir}/src/main/java</directory>
                                <includes>
                                    <include>**/*.xml</include>
                                </includes>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
            </executions>
        </plugin>         

1 0
原创粉丝点击