maven配置文件

maven工程下pom.xml一些常见配置

常用插件配置

    <build>
        <pluginManagement>
            <plugins>
                <!-- compiler插件, 设定JDK版本 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                        <showWarnings>true</showWarnings>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>

                <!-- resource插件 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>2.6</version>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-javadoc-plugin</artifactId>
                    <version>2.9.1</version>
                    <configuration>
                        <show>private</show>
                        <nohelp>true</nohelp>
                    </configuration>
                </plugin>

                <!-- test插件, 仅测试名称为*Test的类, 使用支持分组测试的surefire-junit47 driver -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.16</version>
                    <configuration>
                        <includes>
                            <include>**/*Test.java</include>
                            <argLine>-Dfile.encoding=UTF-8</argLine>
                        </includes>
                        <forkMode>always</forkMode>
                        <argLine>-Dfile.encoding=UTF-8</argLine>
                        <parallel>methods</parallel>
                        <threadCount>4</threadCount>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.apache.maven.surefire</groupId>
                            <artifactId>surefire-junit47</artifactId>
                            <version>2.16</version>
                        </dependency>
                    </dependencies>
                </plugin>

                <!-- 增加更多的Source和Test Source目录插件 -->
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>build-helper-maven-plugin</artifactId>
                    <version>1.8</version>
                </plugin>

                <!-- cobertura 测试覆盖率统计插插件 -->
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>cobertura-maven-plugin</artifactId>
                    <version>2.6</version>
                </plugin>

                <!-- war打包插件, 设定war包名称不带版本号 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <warName>${project.artifactId}</warName>
                    </configuration>
                </plugin>

                <!-- 发布插件 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>

                <!-- jar打包相关插件 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <archive>
                            <manifest>
                                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>


                <!-- clean插件 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>2.5</version>
                </plugin>

                <!-- install插件 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>2.5.1</version>
                </plugin>

                <!-- release插件 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-release-plugin</artifactId>
                    <version>2.5.3</version>
                    <!-- <configuration> SVN的TAG路径 <tagBase>https://svn.mycompany.com/repos/myapplication/releases</tagBase> 
                        </configuration> -->
                </plugin>

                <!-- enforcer规范校验插件, 避免被依赖的依赖引入过期的jar -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-enforcer-plugin</artifactId>
                    <version>1.3.1</version>
                    <executions>
                        <execution>
                            <id>enforce-banned-dependencies</id>
                            <goals>
                                <goal>enforce</goal>
                            </goals>
                            <configuration>
                                <rules>
                                    <requireMavenVersion>
                                        <version>3.0.3</version>
                                    </requireMavenVersion>
                                    <requireJavaVersion>
                                        <version>${java.version}</version>
                                    </requireJavaVersion>
                                </rules>
                                <fail>true</fail>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

                <!-- jetty插件 -->
                <plugin>
                    <groupId>org.mortbay.jetty</groupId> 
                    <artifactId>maven-jetty-plugin</artifactId> 
                    <version>8.1.16.v20140903</version>
                    <configuration> 
                        <connectors> 
                           <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector"> 
                                <port>9999</port> 
                                <maxIdleTime>60000</maxIdleTime> 
                            </connector> 
                        </connectors> 
                    </configuration>    
                </plugin>

                <!-- tomcat插件 -->
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.2</version>
                </plugin>

                <!-- assembly插件 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.4</version>
                </plugin>

                <!-- dependency相关插件 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.8</version>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>versions-maven-plugin</artifactId>
                    <version>2.1</version>
                </plugin>

                <!-- ant插件 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <version>1.7</version>
                </plugin>

                <!-- exec java 插件 -->
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>
                    <version>1.2.1</version>
                </plugin>

                <!-- source -->
                <plugin>
                    <artifactId>maven-source-plugin</artifactId>
                    <version>2.1</version>
                    <configuration>
                        <attach>true</attach>
                    </configuration>
                    <executions>
                        <execution>
                            <phase>compile</phase>
                            <goals>
                                <goal>jar</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

jar包依赖配置

<!-- 预定义依赖项的version,scope与exclusions,子项目中只需定义groupId,artifactId 即可 -->
    <dependencyManagement>
        <dependencies>
            <!-- NumberUtils工具类 -->
            <dependency>
                <groupId>commons-lang</groupId>
                <artifactId>commons-lang</artifactId>
                <version>2.6</version>
            </dependency>
        <dependencies>
    <dependencyManagement>

常用命令

  1. 构建打包:mvn -Dmaven.test.skip=true clean install
  2. 本地建立jar包:mvn install:install-file -DgroupId=FCKeditor -DartifactId=FCKeditor -Dversion=2.3 -Dpackaging=jar -Dfile=d:\FCKeditor-2.3.jar
  3. mvn jetty:run -Djetty.port=9999
  4. 部署到远程仓库

部署远程jar的配置

setting.xml本地文件配置

<settings>  
...  
<servers>  
  <server>  
    <id>nexus-releases</id>  
    <username>admin</username>  
    <password>admin123</password>  
  </server>  
  <server>  
    <id>nexus-snapshots</id>  
    <username>admin</username>  
    <password>admin123</password>  
  </server>    
</servers>  
...  
</settings>  

maven工程pom.xml文件的配置

<project>  
...  
<distributionManagement>  
  <repository>  
    <id>nexus-releases</id>  
      <name>Nexus Release Repository</name>  
      <url>http://127.0.0.1:8080/nexus/content/repositories/releases/</url>  
  </repository>  
  <snapshotRepository>  
    <id>nexus-snapshots</id>  
    <name>Nexus Snapshot Repository</name>  
    <url>http://127.0.0.1:8080/nexus/content/repositories/snapshots/</url>  
  </snapshotRepository>  
</distributionManagement>  
...  
</project>  

使用nexus搭建私服可参见使用nexus搭建maven私服
maven私服搭建

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值