1新建4个文件夹hello/src/main/java 然后把源代码放进去
2pom.xml文件放到hello下面,也就是项目的根目录下面。
内容如下:
<?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>com.maven</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Maven test hello project</name>
</project>
groupId artifactId version 是个坐标 来确定唯一性
name是友好的提示
java类:Hi.java
package com.maven.test;
public class Hi {
public String sayhi(){
return "hi";
}
public static void main(String[] args) {
System.out.println(new Hi().sayhi());
}
}
D:\maven\hello>mvn clean compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven test hello project 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ test ---
[INFO] Deleting D:\maven\hello\target
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ test ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\maven\hello\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ test ---
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 1 source file to D:\maven\hello\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.219s
[INFO] Finished at: Fri Dec 09 16:51:48 CST 2011
[INFO] Final Memory: 5M/15M
[INFO] ------------------------------------------------------------------------
2pom.xml文件放到hello下面,也就是项目的根目录下面。
内容如下:
<?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>com.maven</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Maven test hello project</name>
</project>
groupId artifactId version 是个坐标 来确定唯一性
name是友好的提示
java类:Hi.java
package com.maven.test;
public class Hi {
public String sayhi(){
return "hi";
}
public static void main(String[] args) {
System.out.println(new Hi().sayhi());
}
}
D:\maven\hello>mvn clean compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven test hello project 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ test ---
[INFO] Deleting D:\maven\hello\target
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ test ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\maven\hello\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ test ---
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 1 source file to D:\maven\hello\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.219s
[INFO] Finished at: Fri Dec 09 16:51:48 CST 2011
[INFO] Final Memory: 5M/15M
[INFO] ------------------------------------------------------------------------