mvn

建立偶过个模块的mvn项目

使用下面的命令创建子项目

mkdir calc
cd calc
mvn archetype:generate    -DgroupId=com.stcalc   -DartifactId=common -DinteractiveMode=false
mvn archetype:generate    -DgroupId=com.stcalc   -DartifactId=business-rule -DinteractiveMode=false
mvn archetype:generate    -DgroupId=com.stcalc   -DartifactId=sheduler -DinteractiveMode=false

mvn archetype:generate   -DarchetypeArtifactId=maven-archetype-webapp   -DgroupId=com.github.bisone   -DartifactId=ui-webapp -DinteractiveMode=false

在 calc目录下创建pom.xml文件

使用 <modules> 标签定义子项目

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <properties>
    <full.version>1.0.0</full.version>
  </properties>

  <groupId>com.stcalc </groupId>
  <artifactId>calc</artifactId>
  <version>${full.version}</version>
  <packaging>pom</packaging>

  <modules>
    <module>common</module>
    <module>business-rule</module>
    <module>sheduler</module>
    <module>web</module>
  </modules>
</project>

修改子项目pom.xml定义parent

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
      <groupId>com.stcalc</groupId>
      <artifactId>calc</artifactId>
      <version>${full.version}</version>
  </parent>

  <groupId>com.stcalc</groupId>
  <artifactId>common</artifactId>
  <packaging>jar</packaging>
  <version>${full.version}</version>
   <name>common</name>
  <url>http://maven.apache.org</url>


  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

Jetty plugin

    <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>8.1.9.v20130131</version>
            <configuration>
<contextXml>${basedir}/src/main/webapp/WEB-INF/jetty-context.xml</contextXml>
                    <stopKey>CTRL+C</stopKey>
                    <stopPort>8999</stopPort>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <webAppConfig>
                            <contextPath>/</contextPath>
                    </webAppConfig>
                    <connectors>
                      <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                        <port>9090</port>
                        <maxIdleTime>60000</maxIdleTime>
                      </connector>
                    </connectors>

            </configuration>
    </plugin>

jetty-context.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
        "http://www.eclipse.org/jetty/configure.dtd">

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    <Call name="setAttribute">
        <Arg>org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</Arg>
        <Arg>.*/.*jsp-api-[^/]\.jar$|./.*jsp-[^/]\.jar$|./.*taglibs[^/]*\.jar$</Arg>
    </Call>
</Configure>

mvn dependency:tree

settings

cat ~/.m2/settings.xml

<?xml version="1.0" encoding="UTF-8"?>
<settings
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"
    xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <profiles>

   <profile>
      <id>sonar</id>
    <activation>
      <activeByDefault>true</activeByDefault>
    </activation>
    <properties>
      <!-- Example for MySQL-->
      <sonar.__my_company_1__bc.url>
        __my_company_1__bc:h2:tcp://localhost:9092/sonar
      </sonar.__my_company_1__bc.url>
      <sonar.__my_company_1__bc.username>sonar</sonar.__my_company_1__bc.username>
      <sonar.__my_company_1__bc.password>sonar</sonar.__my_company_1__bc.password>

      <!-- Optional URL to server. Default value is http://localhost:9000 -->
      <sonar.host.url>
        http://localhost:9000
      </sonar.host.url>
    </properties>
  </profile>
</profiles>

<proxies>
<proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>127.0.0.1</host>
      <port>8087</port>
      <nonProxyHosts></nonProxyHosts>
</proxy>
</proxies>
</settings>

下载源代码

mvn dependency:sources
mvn dependency:resolve -Dclassifier=javadoc

测试

Run Unit Test See below examples to run unit test with Maven.

Example 1 To run the entire unit test (TestApp1 and TestApp2), issue this command :

mvn test

Example 2 To run single test (TestApp1), issue this command :

mvn -Dtest=TestApp1 test

Comments

comments powered by Disqus