Maven工程常用插件
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>
编译器插件配置
<!--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>
资源过滤配置
<!--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>
可执行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