[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

<?xml version="1.0" encoding="UTF-8"?>
<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>
<name>Maven Hello World Project</name>
</project>

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

package com.juvenxu.mvnbook.helloworld;

public class HelloWorld {
public String sayHello(){
return "Hello Maven";
} public static void main(String[] args) {
System.out.println(new HelloWorld().sayHello());
} }

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

mvn clean compile

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

<?xml version="1.0" encoding="UTF-8"?>
<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>
<name>Maven Hello World Project</name> <dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

package com.juvenxu.mvnbook.helloworld;

import static org.junit.Assert.assertEquals;
import org.junit.Test; public class HelloWorldTest {
@Test
public void testSayHello(){
HelloWorld helloWorld = new HelloWorld();
String result = helloWorld.sayHello();
assertEquals("Hello Maven", result);
} }

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

mvn clean test

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

最新版本maven好像已经不存在下文所述的问题了

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

mvn clean package

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

mvn clean install

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

maven-shade-plugin
<?xml version="1.0" encoding="UTF-8"?>
<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>
<name>Maven Hello World Project</name> <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.helloworld.HelloWorld</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

一键式生成maven工程

脚手架生成maven工程

Archetype

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

mvn archetype:generate

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

[Maven实战-许晓斌]-[第三章] Mave使用入门-LMLPHP

05-07 15:34