- 安装Maven约定,源代码要存放在src/java/main,所以依次创建三个目录
- 按照POM中的<groupId>com.wys.myapp</groupId>和<artifactId>HelloWord</artifactId>创建目录:com\wys\myapp\helloWorld,这个目录是约定存在本项目的Java源代码的,所以最后的目录是:
- 创建HelloWorld.java源代码文件:
package com.wys.myapp.mypackage
public class HelloWorld{
public String SayHello(){
return "hello world";
}
public static void main(String[] args) {
System.out.println(new HelloWorld().SayHello());
}
}
4. 切换到项目的根目录,也就是POM.xml文件所在目录
[c:\~]$ cd D:\MavenTest\HelloWord
5. 执行情况和编译目录
[D:\MavenTest\HelloWord]$ mvn clean compile
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building My first Maven project 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ HelloWord ---
[INFO] Deleting D:\MavenTest\HelloWord\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ HelloWord ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\MavenTest\HelloWord\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ HelloWord ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 1 source file to D:\MavenTest\HelloWord\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.277 s
[INFO] Finished at: 2018-08-02T13:35:47+08:00
[INFO] Final Memory: 13M/108M
[INFO] ------------------------------------------------------------------------
6. 完成后Maven自动新建target目录存在class文件![](http://i2.51cto.com/images/blog/201812/16/f042f37a911d32a6a15b434d2c12de35.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)
7. 在POM.xml下新增加依赖:junit(单元测试jar包)和新的控件
1. 新的依赖
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
2. 新的插件
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<targer>1.5</targer>
</configuration>
</plugin>
</plugins>
</build>
原文地址:http://blog.51cto.com/12074015/2331235
时间: 2024-11-12 06:16:08