阅读(804) (0)

Maven包项目

2017-01-09 19:18:23 更新

Maven教程 - Maven包项目


因为我们已经创建了一个空项目,我们可以去C:\\ mvn_test \\ xmlFileEditor目录并执行以下mvn命令来编译和打包项目。

c:\mvn_test\xmlFileEditor>mvn clean package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building xmlFileEditor 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.6/maven-resources-plugin-2.6.pom
...
...
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to c:\mvn_test\xmlFileEditor\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ xmlFileEditor ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory c:\mvn_test\xmlFileEditor\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ xmlFileEditor ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to c:\mvn_test\xmlFileEditor\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ xmlFileEditor ---
[INFO] Surefire report directory: c:\mvn_test\xmlFileEditor\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.java2s.ide.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.019 sec

Results :

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

[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ xmlFileEditor ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 35.354 s
[INFO] Finished at: 2014-11-03T16:14:01-08:00
[INFO] Final Memory: 25M/369M
[INFO] ------------------------------------------------------------------------
c:\mvn_test\xmlFileEditor>



注意

我们建立了我们的项目并创建了最终的jar文件。

null

从上面的命令我们可以看到两个目标可以结合起来一个命令。

首先,我们可以用 clean goal清除目标目录然后将项目构建输出打包为具有 package 目标的jar。

打包的jar在xmlFileEditor \\ target文件夹中可用为 xmlFileEditor-1.0-SNAPSHOT.jar

测试报告可在xmlFileEditor \\ target \\ surefire-reports文件夹中找到。

Maven编译源代码文件,然后测试源代码文件。然后Maven运行测试用例。 最后Maven创建了包。