Maven工厂常用插件配置

Maven工程常用插件

  1. Tomcat插件配置

    <!--tomcat7插件配置-->
    <plugin>
       <groupId>org.apache.tomcat.maven</groupId>
       <artifactId>tomcat7-maven-plugin</artifactId>
       <version>2.2</version>
        <configuration>
            <!--Tomcat运行端口号-->
            <port>18081</port>
            <!--当前项目所在根路径-->
            <path>/</path>
            <!--GET请求编码为UTF-8-->
            <uriEncoding>UTF-8</uriEncoding>
        </configuration>
    </plugin>
    
  2. 编译器插件配置

      <!--JDK版本配置-->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <target>1.8</target>
                <source>1.8</source>
                <encoding>utf-8</encoding>
            </configuration>
        </plugin>
    
  3. 资源过滤配置

       <!--IDEA是不会编译src的java目录的xml文件,如果需要读取,则需要手动指定哪些配置文件需要读取-->
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
        </resource>
        <!-- 发现在springboot工程中,需要指定,否则会导致编译时文件丢失 -->
        <resource>
            <directory>src/main/resources</directory>
                <includes>
                    <include>*.xml</include>
                </includes>
            </resource>
        </resources>
    </resources>        
    
  4. 可执行jar包打包配置

    • 打包方式一:推荐

      <!--推荐打包方式,当工程中有spring时,可以解决多个spring相关依赖时有可能导致的schema冲突,引起class加载不到等的报错-->    
      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-shade-plugin</artifactId>
          <version>1.7.1</version>
          <executions>
              <execution>
                  <phase>package</phase>
                  <goals>
                      <goal>shade</goal>
                  </goals>
                  <configuration>
                      <transformers>
                          <transformer
                                  implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                              <resource>META-INF/spring.handlers</resource>
                          </transformer>
                          <transformer
                                  implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                              <mainClass>com.test.Jd</mainClass>
                          </transformer>
                          <transformer
                                  implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                              <resource>META-INF/spring.schemas</resource>
                          </transformer>
                      </transformers>
                  </configuration>
              </execution>
          </executions>
      </plugin>
      
    • 打包方式二:

      <!--问题点,当打包spring工程时,可能会出现schema冲突的问题,导致class无法加载-->
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
            <archive>
                <manifest>
                    <mainClass>huxiuSpider.HuxiuSpider</mainClass>
                </manifest>
            </archive>
            <descriptorRefs>
                <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
        </configuration>
      

    • springboot打包:mvn package命令打包

      <!--springboot打包插件-->
      <plugin>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
      
    • 直接打包:

      直接打jar包,没有指定main方法所在类,执行时需要指定main方法所在类

      java -cp xxx.jar com.xxx.Main

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值