标签:style blog io ar color 使用 sp java for
一、编写POM
<groupId>com.shine.myapp</groupId> <artifactId>hello-world</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging>
二、编写主代码
三、编写测试代码
1、添加一个POM的依赖Junit:
<dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.7</version> <scope>test</scope> </dependency> </dependencies>
2、编写单元测试代码。
3、执行mvn clean test,执行顺序:clean:clean、resources:resources、compile:compile、resources:testResources、compile:testCompile。
4、配置maven-compile-plugin支持Java6:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin>
四、打包和运行
1、打包:mvn clean package
2、安装:mvn clean install
3、打可执行Main函数的jar,添加maven-shade-plugin插件:
<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.shine.helloworld.HelloWorld</mainClass> </transformer> </transformers> </configuration> </execution> </executions> </plugin>
运行mvn clean package,出现两个jar:hello-world-0.0.1-SNAPSHOT.jar、original-hello-world-0.0.1-SNAPSHOT.jar,前者是可执行的jar、后者是原始jar。
总结:
mvn clean compile、mvn clean test、mvn clean package、mvn clean install中,
mvn clean test 会执行 mvn clean compile;
mvn clean package 会执行 mvn clean test;
mvn clean install 会执行 mvn clean package。
标签:style blog io ar color 使用 sp java for
原文地址:http://www.cnblogs.com/shine-xh/p/4127703.html