Maven建立Web應用程式專案

隨風yy發表於2018-09-12
1.從Maven模板建立Web專案,輸入如下命令:
mvn archetype:generate -DgroupId=com.yiibai -DartifactId=CounterWebApp -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
C:\software\develop\workplace>mvn archetype:generate -DgroupId=com.test -Dartifa
ctId=testWeb -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false
...
2225: remote -> xyz.luan.generator:xyz-generator (-)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive co
ntains): 1235:
Choose org.apache.maven.archetypes:maven-archetype-quickstart version:
1: 1.0-alpha-1
2: 1.0-alpha-2
3: 1.0-alpha-3
4: 1.0-alpha-4
5: 1.0
6: 1.1
7: 1.3
Choose a number: 7:
[INFO] Using property: groupId = com.test
Define value for property 'artifactId':
Define value for property 'version' 1.0-SNAPSHOT: :
[INFO] Using property: package = com.test
[WARNING] Archetype is not fully configured
[INFO] Using property: groupId = com.test
Define value for property 'artifactId':
[INFO] Using property: version = 1.0-SNAPSHOT
[INFO] Using property: package = com.test
[WARNING] Archetype is not fully configured
[INFO] Using property: groupId = com.test
Define value for property 'artifactId':
[INFO] Using property: version = 1.0-SNAPSHOT
[INFO] Using property: package = com.test
[WARNING] Archetype is not fully configured
[INFO] Using property: groupId = com.test
Define value for property 'artifactId': testWeb
[INFO] Using property: version = 1.0-SNAPSHOT
[INFO] Using property: package = com.test
Confirm properties configuration:
groupId: com.test
artifactId: testWeb
version: 1.0-SNAPSHOT
package: com.test
 Y: :
[INFO] -------------------------------------------------------------------------
---
[INFO] Using following parameters for creating project from Archetype: maven-arc
hetype-quickstart:1.3
[INFO] -------------------------------------------------------------------------
---
[INFO] Parameter: groupId, Value: com.test
[INFO] Parameter: artifactId, Value: testWeb
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: com.test
[INFO] Parameter: packageInPathFormat, Value: com/test
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: com.test
[INFO] Parameter: groupId, Value: com.test
[INFO] Parameter: artifactId, Value: testWeb
[INFO] Project created from Archetype in dir: C:\software\develop\workplace\test
Web
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:16 min
[INFO] Finished at: 2018-09-12T15:03:26+08:00
[INFO] Final Memory: 14M/102M
[INFO] ------------------------------------------------------------------------
2.要匯入這個專案到Eclipse中,需要生成一些 Eclipse 專案的配置檔案,在命令列中輸入:
mvn eclipse:eclipse -Dwtpversion=2.0
C:\software\develop\workplace\testWeb>mvn eclipse:eclipse -Dwtpversion=2.0
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building testWeb 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-eclipse-plugin:2.10:eclipse (default-cli) > generate-resources
@ testWeb >>>
[INFO]
[INFO] <<< maven-eclipse-plugin:2.10:eclipse (default-cli) < generate-resources
@ testWeb <<<
[INFO]
[INFO] --- maven-eclipse-plugin:2.10:eclipse (default-cli) @ testWeb ---
[INFO] Adding support for WTP version 2.0.
[INFO] Using Eclipse Workspace: C:\software\develop\workplace
[INFO] no substring wtp server match.
[INFO] Using as WTP server : Apache Tomcat v7.0
[INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAIN
ER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre8
[INFO] Not writing settings - defaults suffice
[INFO] Wrote Eclipse project for "testWeb" to C:\software\develop\workplace\test
Web.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.059 s
[INFO] Finished at: 2018-09-12T15:10:18+08:00
[INFO] Final Memory: 13M/184M
[INFO] ------------------------------------------------------------------------

注意,此選項 -Dwtpversion=2.0 告訴 Maven 將專案轉換到 Eclipse 的 Web 專案(WAR),而不是預設的Java專案(JAR)。

3.將專案打包,預設是jar包
C:\software\develop\workplace\testWeb>mvn package 
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building testWeb 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) @ testWeb
---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\software\develop\workplace\testWeb
\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ testWeb ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\software\develop\workplace\testWeb\target\c
lasses
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:testResources (default-testResources) @
testWeb ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\software\develop\workplace\testWeb
\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ testW
eb ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\software\develop\workplace\testWeb\target\t
est-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.20.1:test (default-test) @ testWeb ---
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.test.AppTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.024 s -
 in com.test.AppTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ testWeb ---
[INFO] Building jar: C:\software\develop\workplace\testWeb\target\testWeb-1.0-SN
APSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.451 s
[INFO] Finished at: 2018-09-12T15:30:03+08:00
[INFO] Final Memory: 16M/88M
[INFO] ------------------------------------------------------------------------
4.清空target打包後的目錄檔案
C:\software\develop\workplace\testWeb>mvn clean
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building testWeb 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ testWeb ---
[INFO] Deleting C:\software\develop\workplace\testWeb\target
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.324 s
[INFO] Finished at: 2018-09-12T15:29:54+08:00
[INFO] Final Memory: 6M/164M
[INFO] ------------------------------------------------------------------------

相關文章