maven实战 读书笔记(一)

使用maven archetype创建项目的骨架
mvn archetype:generate

mvn archetype:create -DgroupId=com -DartifactId=simple-web 
-DarchetypeArtifactId=maven-archetype-webapp.其中maven-archetype-webapp

编译项目 mvn clean compile
测试项目 mvn clean test
打包项目 mvn clean package
让其他Maven项目可以引用该包 mvn clean install

运行指定的类 mvn exec:java -Dexec.mainClass="com.yl.App"

pom.xml

<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>
  <groupId>com.juvenxu.mvnbook</groupId>
  <artifactId>hello-world</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>hello-world</name>
  <url>http://maven.apache.org</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.7</version>
      <!-- 依赖范围 -->
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
      <plugins>
    <!--在包中添加主类信息-->
      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-shade-plugin</artifactId>
          <version>1.2.1</version>
          <executions>
              <execution>
                  <phase>package</phase>
                  <goals>
                      <goal>shade</goal>
                  </goals>
                  <configuration>
                      <transformers>
                          <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                              <mainClass>com.juvenxu.mvnbook.hellowoeld.App</mainClass>
                          </transformer>
                      </transformers>
                  </configuration>
              </execution>
          </executions>
      </plugin>
      </plugins>
  </build>
</project>

App.java

package com.juvenxu.mvnbook.hellowoeld;
/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
    }
}


你可能感兴趣的:(maven)