Maven建立Web應用程式專案
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] ------------------------------------------------------------------------
相關文章
- 如何建立+管理maven、匯入web專案、xmlMavenWebXML
- 用maven建立專案及maven常用命令Maven
- Python,Django建立web專案project和應用appPythonDjangoWebProjectAPP
- Maven Web 應用MavenWeb
- 建立Maven專案出錯Maven
- maven 專案的建立入門Maven
- maven專案增加web.xmlMavenWebXML
- mvn 建立java專案 web專案JavaWeb
- idea建立web專案IdeaWeb
- Visual Studio 2005 如何建立“Web 應用程式”Web
- Springboot建立maven多模組專案Spring BootMaven
- 建立Maven專案出錯 pom出錯Maven
- Maven建立專案遇到導包錯誤:Maven
- 在idea中利用spingboot建立maven專案IdeabootMaven
- 如何建立一個Maven專案(eclipse版本)MavenEclipse
- Electron桌面應用程式從建立專案、啟動專案到打包程式的詳細過程
- 首次使用ideal構建maven專案webIdeaMavenWeb
- IDEA Maven Web專案的install和runIdeaMavenWeb
- spring boot 建立web專案(IDEA)Spring BootWebIdea
- idea社群版建立web專案IdeaWeb
- IDEA建立動態Web專案IdeaWeb
- serverless 專案配置及建立helloworld應用(二)Server
- IDEA建立Maven專案中踩過的坑IdeaMaven
- IntelliJ IDEA 建立Spring+SpringMVC+mybatis+maven專案IntelliJIdeaSpringMVCMyBatisMaven
- 使用Maven,idea建立web專案啟動不了,war exploded: Artifact is being deployed, please wait...MavenIdeaWebAI
- maven非web專案整合mbatis實現CRUDMavenWebBAT
- IDEA新建Maven Java Web專案-詳細教程IdeaMavenJavaWeb
- 【Maven實戰技巧】「外掛使用專題」Maven-Archetype外掛建立自定義maven專案骨架Maven
- IDEA設定預設Maven(使用idea maven archetype建立專案時,專案建立慢或者不完整,缺失部分目錄)IdeaMaven
- pom-建立web專案錯誤Web
- Idea intellij jdk 1.7通過maven建立Springboot專案IdeaIntelliJJDKMavenSpring Boot
- 用Idea建立第一個spring web專案,一直resolving dependencies XXX (載入特別慢http://repo1.maven.org/maven2)IdeaSpringWebHTTPMaven
- 小白手把手教學怎麼用maven建立一個Springboot專案MavenSpring Boot
- 初步建立小程式專案
- sbt建立play framework(play!)scala web專案FrameworkWeb
- MyEclipse - 通過Maven建立WebApp專案時,生成的專案名中總是包含Maven Webapp的問題EclipseMavenWebAPP
- ASP.NET 微軟Web應用示例程式走廊-專案解決方案ASP.NET微軟Web
- 你竟然沒用 Maven 構建專案?Maven