Marven入门
Marven是Java自动编译、打包工具的工具类
1,安装
Marven是绿色软件,下载解压后,把bin目录加入到Path环境变量即可
在cmd命令行下输入下面命令测试配置是否正确
mvn -v
2,Java源码,配置文件建立
参照下面结构,建立文件夹。
└── src
└── main
└── java
└── hello
在hello目录下建立Java文件,pom.xml文件
package hello; public class HelloWorld { public static void main(String[] args) { Greeter greeter = new Greeter(); System.out.println(greeter.sayHello()); } }
package hello; public class Greeter { public String sayHello() { return "Hello world!"; } }
<?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/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.springframework</groupId> <artifactId>gs-maven</artifactId> <packaging>jar</packaging> <version>0.1.0</version> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>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>hello.HelloWorld</mainClass> </transformer> </transformers> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
3,编译、打包、运行
在cmd下执行下面命令
mvn compile
mvn package
运行:
cd E:\JavaStudy\Maven\target
java -jar gs-maven-0.1.0.jar
参考资料:http://spring.io/guides/gs/maven
签名:删除冗余的代码最开心,找不到删除的代码最痛苦!