【测试入门系列】Maven是什么

Maven是什么?先用起来。结论在本文最后。

使用步骤

安装好maven后,在命令行执行如下命令,用maven初始化一个叫做helloworld的项目:

$mvn archetype:generate -DgroupId=com.mycompany.helloworld -DartifactId=helloworld -Dpackage=com.mycompany.helloworld -Dversion=1.0-SNAPSHOT

一路回车,最后得到一个helloworld目录:

[raywill 562 ~/code/test/helloworld]
$tree
.
├── pom.xml
└── src
    ├── main
    │   └── java
    │       └── com
    │           └── mycompany
    │               └── helloworld
    │                   └── App.java
    └── test
        └── java
            └── com
                └── mycompany
                    └── helloworld
                        └── AppTest.java

11 directories, 3 files

工程初始化好后就可以开始写代码,代码搞定,执行编译打包:

mvn package

打包过程会运行测试程序,自动下载依赖的包,最后target/目录下生成一个jar包,就是我们最后的产品。

运行产品的方法

java -cp target/helloworld-1.0-SNAPSHOT.jar com.mycompany.helloworld.App

参数说明:

java [ options ] class [ argument...  ]

       -classpath classpath
       -cp classpath
              Specifies a list of directories, JAR archives, and ZIP archives to search for class files. Class path entries are separated by colons (:). Specifying -classpath or -cp overrides any setting of the CLASSPATH environment variable.
              If -classpath and -cp are not used and CLASSPATH is not set, the user class path consists of the current directory (.).

上面,-cp target/helloworld-1.0-SNAPSHOT.jar 是 options,指定了jar包的位置。com.mycompany.helloworld.App 是 class,说明要运行哪一端逻辑。可以推测:一个jar里面可以有多个运行入口,可通过命令行指定。

结论

Maven 是一个代码框架生成工具,同时也是一个打包工具,类似于 nodejs 中的 npm + 脚手架。

上面的整过过程都没有涉及到 Eclipse,Eclipse 如果希望使用 Maven,需要安装插件。可以猜想,插件的功能就是帮助 Eclipse 调用 Maven 的各种命令,并显示结果。

参考文献

http://www.oracle.com/technetwork/cn/community/java/apache-maven-getting-started-1-406235-zhs.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值