第3章:Maven使用入门/3.2 编写源代码

  • 编写源代码
  1. 安装Maven约定,源代码要存放在src/java/main,所以依次创建三个目录
  2. 按照POM中的<groupId>com.wys.myapp</groupId>和<artifactId>HelloWord</artifactId>创建目录:com\wys\myapp\helloWorld,这个目录是约定存在本项目的Java源代码的,所以最后的目录是:
  3. 创建HelloWorld.java源代码文件:
  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文件
  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>

      》》》》》未完:易学笔记-Maven教程--入门就看这一篇就够了》》》》》

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

易学笔记(qq:1776565180)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值