第3章:Maven使用入门/3.2 编写源代码
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第3章:Maven使用入门/3.2 编写源代码相关的知识,希望对你有一定的参考价值。
- 编写源代码
- 安装Maven约定,源代码要存放在src/java/main,所以依次创建三个目录
- 按照POM中的<groupId>com.wys.myapp</groupId>和<artifactId>HelloWord</artifactId>创建目录:comwysmyapphelloWorld,这个目录是约定存在本项目的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:MavenTestHelloWord
5. 执行情况和编译目录
[D:MavenTestHelloWord]$ 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:MavenTestHelloWord arget
[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:MavenTestHelloWordsrcmain
esources
[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:MavenTestHelloWord argetclasses
[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>
以上是关于第3章:Maven使用入门/3.2 编写源代码的主要内容,如果未能解决你的问题,请参考以下文章
《SystemVerilog验证-测试平台编写指南》学习 - 第3章 过程语句和子程序
[架构之路-49]:目标系统 - 系统软件 - Linux下的网络通信-5-快速数据平面开发套件DPDK - 快速部署软件入门指南