本教程將介紹如何使用ymate-maven-extension
擴展工具,快速搭建基於YMP框架的Java工程,及如何經過Maven完成編譯、運行等一系列操做。git
項目主頁:http://git.oschina.net/suninformation/ymate-maven-extensionweb
目前YMP擴展工具支持如下幾種項目模板:apache
標準Java工程,已集成YMP-Core等依賴;瀏覽器
JavaWeb工程,已集成YMP-WebMVC框架相關依賴和完整的參數配置。tomcat
YMP模塊工程,提供Demo示例及JUint測試代碼。mvc
YMP服務工程,分別提供TCP、UDP客戶端和服務端示例程序及相關配置。app
注:若是您還沒有編譯、安裝YMPv2框架包,請前往YMP官網下載。框架
手動編譯並安裝ymate-maven-extension
擴展工具到本地Maven倉庫:webapp
步驟1:下載擴展工具源碼maven
執行命令:git clone https://git.oschina.net/suninformation/ymate-maven-extension.git
步驟2:編譯並安裝到本地Maven倉庫
執行命令: cd ymate-maven-extension mvn clean install
步驟1:開啓本地archetype嚮導
執行命令:mvn archetype:generate -DarchetypeCatalog=local
屏幕輸出:
Choose archetype: 1: local -> net.ymate.maven.archetypes:ymate-archetype-quickstart (YMP Quickstart Archetype.) 2: local -> net.ymate.maven.archetypes:ymate-archetype-webapp (YMP Webapp Archetype.) 3: local -> net.ymate.maven.archetypes:ymate-archetype-module (YMP Module Archetype.) 4: local -> net.ymate.maven.archetypes:ymate-archetype-serv (YMP Serv Archetype.) Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): :
屏幕輸出,接下來要按屏幕提示進行設置:
Define value for property 'groupId': : net.ymate.platform.examples Define value for property 'artifactId': : ymp-examples-webapp Define value for property 'version': 1.0-SNAPSHOT: : Define value for property 'package': net.ymate.platform.examples: : Confirm properties configuration: groupId: net.ymate.platform.examples artifactId: ymp-examples-webapp version: 1.0-SNAPSHOT package: net.ymate.platform.examples Y: :
回車鍵確認後,開始生成工程結構:
[INFO] ---------------------------------------------------------------------------- [INFO] Using following parameters for creating project from Archetype: ymate-archetype-webapp:1.0-SNAPSHOT [INFO] ---------------------------------------------------------------------------- [INFO] Parameter: groupId, Value: net.ymate.platform.examples [INFO] Parameter: artifactId, Value: ymp-examples-webapp [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] Parameter: package, Value: net.ymate.platform.examples [INFO] Parameter: packageInPathFormat, Value: net/ymate/platform/examples [INFO] Parameter: package, Value: net.ymate.platform.examples [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] Parameter: groupId, Value: net.ymate.platform.examples [INFO] Parameter: artifactId, Value: ymp-examples-webapp [INFO] project created from Archetype in dir: /Users/suninformation/Temp/ymp-examples-webapp [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1:08.723s [INFO] Finished at: Thu Mar 17 11:00:54 CST 2016 [INFO] Final Memory: 13M/155M [INFO] ------------------------------------------------------------------------
至此,基於擴展工具快速搭建YMP工程已完成!
首先,進入新建立的工程目錄中,執行以下命令:
cd ymp-examples-webapp
而後,經過Maven進行代碼編譯並打包,執行以下命令:
mvn clean compile package
屏幕輸出:
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building ymp-examples-webapp 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] ......(此處省略10000字) [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.582s [INFO] Finished at: Thu Mar 17 11:43:19 CST 2016 [INFO] Final Memory: 17M/212M [INFO] ------------------------------------------------------------------------
最後,經過Maven啓動Tomcat服務並運行war包,執行以下命令:
mvn tomcat:run-war
屏幕輸出:
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building ymp-examples-webapp 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] ......(此處省略10000字) [INFO] [INFO] <<< tomcat-maven-plugin:1.1:run-war (default-cli) @ ymp-examples-webapp <<< [INFO] [INFO] --- tomcat-maven-plugin:1.1:run-war (default-cli) @ ymp-examples-webapp --- [INFO] Running war on http://localhost:8080/ymp-examples-webapp [INFO] Creating Tomcat server configuration at /Users/suninformation/Temp/ymp-examples-webapp/target/tomcat 三月 17, 2016 11:48:31 上午 org.apache.catalina.startup.Embedded start 信息: Starting tomcat server 三月 17, 2016 11:48:32 上午 org.apache.catalina.core.StandardEngine start 信息: Starting Servlet Engine: Apache Tomcat/6.0.29 [INFO] YMP - __ ____ __ ____ ____ \ \ / / \/ | _ \ __ _|___ \ \ V /| |\/| | |_) | \ \ / / __) | | | | | | | __/ \ V / / __/ |_| |_| |_|_| \_/ |_____| Website: http://www.ymate.net/ [INFO] YMP - Initializing ymate-platform-core-2.0.0-GA build-20160315-0206 - debug:true [INFO] Validations - Initializing ymate-platform-validation-2.0.0-GA build-20160315-0206 [INFO] WebMVC - Initializing ymate-platform-webmvc-2.0.0-GA build-20160315-0206 [INFO] Caches - Initializing ymate-platform-cache-2.0.0-GA build-20160315-0206 [INFO] Logs - Initializing ymate-platform-log-2.0.0-GA build-20160315-0206 [INFO] Cfgs - Initializing ymate-platform-configuration-2.0.0-GA build-20160315-0206 [INFO] ......(此處省略10000字) [INFO] YMP - Initialization completed, Total time: 839ms 三月 17, 2016 11:48:33 上午 org.apache.coyote.http11.Http11Protocol init 信息: Initializing Coyote HTTP/1.1 on http-8080 三月 17, 2016 11:48:33 上午 org.apache.coyote.http11.Http11Protocol start 信息: Starting Coyote HTTP/1.1 on http-8080
看到上面輸出信息,說明Tomcat服務已啓動,並已成功運行war包。
請打開瀏覽器訪問:http://localhost:8080/ymp-examples-webapp/
瀏覽器輸出內容:
Hello YMP world!
Congratulations!,恭喜你成功使用Maven完成了對YMP項目的建立、編譯、運行等一系列操做,是否是很簡單,你們能夠動手嘗試一下!
YMP不只提供便捷的Web及其它Java項目的快速開發體驗,也將不斷提供更多豐富的項目實踐經驗。
感興趣的小夥伴兒們能夠加入 官方QQ羣480374360,一塊兒交流學習,幫助YMP成長!
瞭解更多有關YMP框架的內容,請訪問官網:http://www.ymate.net/