使用groupId定义项目;使用artifactId定义模块html
e.g
组织域名: zoo.com
项目名: cat 模块名: dao
项目坐标:java
<groupId>com.zoo.cat</groupId> <artifactId>cat-dao</artifactId> <version>1.1.1-alpha</version>
使用此种规划可有效防止混淆,使项目结构清晰。web
<主版本>.<次版本>.<增量版本>-<限定符>
主版本 -- 大型架构变动
次版本 -- 特性增长
增量版本 -- bug修复
限定符 -- alpha,beta....
打包时还会用到classifier, 如: dog-cli-1.0-sources.jar,dog-cli-1.0-javadoc.jar
其中的sources和javadoc 就是classifier。可使用Maven Assembly Plugin 来生成。shell
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
pom.xml中加入:apache
<properties> <project.build.sourceEncoding>GBK</project.build.sourceEncoding> </properties>
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.5:war (default-war) on project WlanTroubleshootingQuery: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode) -> [Help 1]
配置插件属性,加入failOnMissingWebXml字段:架构
<plugin> <!--http://maven.apache.org/plugins/maven-war-plugin/--> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.5</version> <configuration> <warName>troubleshooting</warName> <failOnMissingWebXml>false</failOnMissingWebXml> <webResources> <resource> <directory>${project.basedir}/src/main/resources</directory> <targetPath>WEB-INF/classes</targetPath> </resource> </webResources> <executions> <execution> <id>create-war-file</id> <phase>package</phase><!-- 要绑定到的生命周期的阶段 --> <goals> <goal>war</goal><!-- 要绑定的插件的目标 --> </goals> </execution> </executions> </configuration> </plugin>
<!--pom.xml--> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.4.3</version> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>com.ghca.Helloworld</mainClass> </transformer> </transformers> </configuration> </execution> </executions> </plugin> </plugins> </build>
mvn dependency:tree
maven默认编译版本时jdk1.5. 有时候忘记修改就会编译失败. 修改setting.xml文件 配置默认profile可解决. 这里同时配置了文件编码. 解决 "[WARNING] Using platform encoding" 警告app
<profiles> <profile> <id>UTF8-JDK1.8</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.8</jdk> <!-- 当jdk为1.8时本profile生效 --> </activation> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> </properties> </profile> </profiles>
参考: Introduction to Build Profileswebapp
#打war包maven
<dependencies> <!-- 本地包 --> <dependency> <groupId>com.qq</groupId> <artifactId>qq_connect</artifactId> <version>2.0</version> <scope>system</scope> <systemPath>${project.basedir}/src/main/webapp/WEB-INF/lib/QQSdk4J.jar</systemPath> </dependency> </dependencies> <build> <finalName>AuthServer</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.1</version> <configuration> <!--JDK版本--> <source>1.7</source> <target>1.7</target> <!--编译使用的字符集--> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <!--http://maven.apache.org/plugins/maven-war-plugin/--> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.4</version> <configuration> <!--war包文件名--> <warName>authServer</warName> <!--指定web.xml文件位置--> <webXml>src/main/webapp/WEB-INF/web.xml</webXml> <!--指定各类资源文件--> <webResources> <resource> <directory>${project.basedir}/src/main/resources</directory> <targetPath>WEB-INF/classes</targetPath> </resource> </webResources> </configuration> </plugin> </plugins> </build>