首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

用 Maven 编译最简略的 java 程序

2013-03-12 
用 Maven 编译最简单的 java 程序参考地址: http://maven.apache.org/guides/getting-started/maven-in-fi

用 Maven 编译最简单的 java 程序

参考地址: http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

下载 Maven 地址:http://maven.apache.org/download.cgi#Installation

设置 Maven 的环境变量: 变量名:M2_HOME   变量值: C:\apache-maven-3.0.5

设置 Path 的环境变量:C:\apache-maven-3.0.5\bin;

建立maven的目录结构,我在这个基础上新增了A.java B.java 和相应的测试类

my_app
|-- pom.xml
`-- src
    |-- main
    |   `-- java
    |       `-- com
    |           `-- xjh
    |               `-- app
    |                   `-- App.java
    `-- test
        `-- java
            `-- com
                `-- xjh
                    `-- app
                        `-- AppTest.java

App.java



在控制台运行

D:\maven_test\my_app>mvn package

运行结果:

D:\maven_test\my_app>mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------
[INFO] Building Maven Quick Start Archetype 1.0-SNAPSHOT
[INFO] ------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ my_app ---

[debug] execute contextualize
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\maven_test\my_app\src\main\resourc
es
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ my_app ---
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. buil
d is platform dependent!
[INFO] Compiling 3 source files to D:\maven_test\my_app\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ my
_app ---
[debug] execute contextualize
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e
. build is platform dependent!
[INFO] skip non existing resourceDirectory D:\maven_test\my_app\src\test\resourc
es
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ my_ap
p ---
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. buil
d is platform dependent!
[INFO] Compiling 4 source files to D:\maven_test\my_app\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ my_app ---
[INFO] Surefire report directory: D:\maven_test\my_app\target\surefire-reports

-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.xjh.app.AllTest
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.037 sec
Running com.xjh.app.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 sec
Running com.xjh.app.ATest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec
Running com.xjh.app.BTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 sec

Results :

Tests run: 6, Failures: 0, Errors: 0, Skipped: 0

[INFO]
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ my_app ---
[INFO] Building jar: D:\maven_test\my_app\target\my_app-1.0-SNAPSHOT.jar
[INFO] ------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------
[INFO] Total time: 1.973s
[INFO] Finished at: Fri Mar 08 21:44:35 CST 2013
[INFO] Final Memory: 11M/28M
[INFO] ------------------------------------
D:\maven_test\my_app>

热点排行