本教程将介绍如何使用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/