rose学习

转载自五四陈科学院[http://www.54chen.com]

rose手册第二章:配置与使用

Posted on 2012-04-10 by 54chen

ROSE

2.1 基础环境

* 普通的pc机,del 380
* ubuntu 10.04基本不升级
* java version "1.6.0_29"
* eclipse
* m2clipse
* 茶一杯

2.2 maven简介

* maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具。如果你已经有十次输入同样的Ant targets来编译你的代码、jar或者war、生成javadocs,你一定会自问,是否有一个重复性更少却能同样完成该工作的方法。Maven便提供了这样一种选择,将你的注意力从作业层转移到项目管理层。Maven项目已经能够知道如何构建和捆绑代码,运行测试,生成文档并宿主项目网页。
* maven对一个项目进入了固定的默认目录定义:
* src/main/java 写主要的java实现
* src/main/resources 写主要的配置文件
* src/test/java 写test case
* src/test/resources 写test case所需要的配置文件
* src/main/webapp [war项目特有]web项目的对外目录
* src/main/webapp/WEB-INF [war项目特有]web项目配置web.xml目录

2.3 项目建立

* 打开eclipse(需要提前安装好m2clipse插件)
* new -> other -> maven -> maven project
* create a simple project
* next
* group id:com.54chen
* artifact id:rose-example
* packaging: war
* finished

2.4 基础配置三步走

1)点火:基础的pom文件 
打开2.3建立好的项目,打开pom.xml,添加下面的段落到project中:

  1. <dependencies>
  2. <dependency>
  3. <groupId>com.54chen</groupId>
  4. <artifactId>paoding-rose-scanning</artifactId>
  5. <version>1.0-SNAPSHOT</version>
  6. </dependency>
  7. <dependency>
  8. <groupId>com.54chen</groupId>
  9. <artifactId>paoding-rose</artifactId>
  10. <version>1.0-SNAPSHOT</version>
  11. </dependency>
  12. <dependency>
  13. <groupId>com.54chen</groupId>
  14. <artifactId>paoding-rose-portal</artifactId>
  15. <version>1.0-SNAPSHOT</version>
  16. </dependency>
  17. <dependency>
  18. <groupId>com.54chen</groupId>
  19. <artifactId>paoding-rose-jade</artifactId>
  20. <version>1.1-SNAPSHOT</version>
  21. </dependency>
  22. </dependencies>

上述是rose环境最基础的依赖包。再添加一点常见的编译设置:

  1. <build>
  2. <resources>
  3. <resource>
  4. <directory>src/main/resources</directory>
  5. <includes>
  6. <include>**/*.*</include>
  7. </includes>
  8. </resource>
  9. </resources>
  10. <plugins>
  11. <plugin>
  12. <groupId>org.apache.maven.plugins</groupId>
  13. <artifactId>maven-war-plugin</artifactId>
  14. <version>2.0.2</version>
  15. <configuration>
  16. <webResources>
  17. <resource>
  18. <targetPath>WEB-INF</targetPath>
  19. <filtering>true</filtering>
  20. <directory>src/main/resources</directory>
  21. <includes>
  22. <include>**/*.xml</include>
  23. <include>**/*.properties</include>
  24. </includes>
  25. <targetPath>WEB-INF</targetPath>
  26. </resource>
  27. </webResources>
  28. </configuration>
  29. </plugin>
  30. <plugin>
  31. <groupId>org.apache.maven.plugins</groupId>
  32. <artifactId>maven-compiler-plugin</artifactId>
  33. <configuration>
  34. <source>1.6</source>
  35. <target>1.6</target>
  36. <fork>true</fork>
  37. <verbose>true</verbose>
  38. <encoding>UTF-8</encoding>
  39. <compilerArguments>
  40. <sourcepath>
  41. ${project.basedir}/src/main/java
  42. </sourcepath>
  43. </compilerArguments>
  44. </configuration>
  45. </plugin>
  46. <plugin>
  47. <groupId>org.apache.maven.plugins</groupId>
  48. <artifactId>maven-surefire-plugin</artifactId>
  49. <configuration>
  50. <!-- 忽略测试 -->
  51. <skip>true</skip>
  52. </configuration>
  53. </plugin>
  54. </plugins>
  55. </build>

上述是编译设置,也是放在project段落里。

2)松离合:必不可少的web.xml 
在src/main/webapp/WEB-INF文件夹下建立web.xml:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  4. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  5. id="WebApp_ID" version="2.5">
  6. <display-name>rose-example</display-name>
  7. <welcome-file-list>
  8. <welcome-file>index.html</welcome-file>
  9. <welcome-file>index.htm</welcome-file>
  10. <welcome-file>index.jsp</welcome-file>
  11. <welcome-file>default.html</welcome-file>
  12. <welcome-file>default.htm</welcome-file>
  13. <welcome-file>default.jsp</welcome-file>
  14. </welcome-file-list>
  15. <context-param>
  16. <param-name>log4jConfigLocation</param-name>
  17. <param-value>/WEB-INF/log4j.xml</param-value>
  18. </context-param>
  19. <listener>
  20. <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  21. </listener>
  22. <filter>
  23. <filter-name>roseFilter</filter-name>
  24. <filter-class>net.paoding.rose.RoseFilter</filter-class>
  25. </filter>
  26. <filter-mapping>
  27. <filter-name>roseFilter</filter-name>
  28. <url-pattern>/*</url-pattern>
  29. <dispatcher>REQUEST</dispatcher>
  30. <dispatcher>FORWARD</dispatcher>
  31. <dispatcher>INCLUDE</dispatcher>
  32. </filter-mapping>
  33. </web-app>

3)踩油门:applicationContext.xml 
src/main/resources/applicationContext.xml是spring环境的油门,所有包的扫描和启动都在这里定义:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
  4. xsi:schemaLocation="http://www.springframework.org/schema/beans
  5. http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
  6. http://www.springframework.org/schema/context
  7. http://www.springframework.org/schema/context/spring-context-2.5.xsd"
  8. default-lazy-init="true">
  9. <!-- 自动扫描 -->
  10. <context:annotation-config />
  11. <context:component-scan base-package="com.chen">
  12. </context:component-scan>
  13. </beans>

2.5 hello world

* 在src/main/java上右键 -> new -> package -> name: com.chen
* 在com.chen上右键 -> new -> package -> com.chen.controllers [controllers是rose框架默认的加载controller的package name]
* 在com.chen.controllers上右键 -> new -> class -> HelloController [*Controller是rose框架默认的controller层的class后缀]
* 打开HelloController这个类
* 在public class HelloController添加注解@Path("") [Path注解是rose框架提供的标识每个controller的对外访问时的基础路径]
* 在HelloController中添加方法

  1. /**
  2. * @author 54chen(陈臻) [[email protected] [email protected]]
  3. * @since 2012-4-10 上午11:14:46
  4. */
  5. package com.chen.controllers;
  6. import net.paoding.rose.web.annotation.Path;
  7. import net.paoding.rose.web.annotation.rest.Get;
  8. @Path("")
  9. public class HelloController {
  10. @Get("")
  11. public String index() {
  12. return "@hello world";
  13. }
  14. }

* [Get注解是rose框架提供的标识一个http访问是get还是post或者是其他,并且会将path与get中的字符串连接成一个url]
* 上述代码可以从浏览器访问:http://localhost/。
* 下述代码可以从浏览器访问:http://localhost/hello/world [注意path与get中的参数]。

  1. /**
  2. * @author 54chen(陈臻) [[email protected] [email protected]]
  3. * @since 2012-4-10 上午11:14:46
  4. */
  5. package com.chen.controllers;
  6. import net.paoding.rose.web.annotation.Path;
  7. import net.paoding.rose.web.annotation.rest.Get;
  8. @Path("/hello/")
  9. public class HelloController {
  10. @Get("world")
  11. public String index() {
  12. return "@hello world";
  13. }
  14. }

__EOF__

* 动态更新版本地址在:https://github.com/XiaoMi/rose/tree/master/chapter_2
* 文中所提及的代码在:https://github.com/XiaoMi/rose/rose-example

原创文章如转载,请注明:转载自五四陈科学院[http://www.54chen.com
本文链接: http://www.54chen.com/java-ee/rose-manual-2.html

This entry was posted in java and tagged rose. Bookmark the permalink.

← 54chen Twitter memo 2012-04-08

54chen Twitter memo 2012-04-15 →

7 Responses to “rose手册第二章:配置与使用”

时间: 2025-01-17 20:26:34

rose学习的相关文章

第二个目标:两个月并行学习设计模式、UML、ROSE

两个月并行学习设计模式.UML.ROSE: 参考资料:HEAD_FIRST设计模式(中文版).pdf.[大象Thinking.in.UML].ThinkingInUML.pdf(UML入门教程(中文版).pdf和UML其它详细教程,重点是项目中常见应用的几个图).RationalRos画图.docx 要     求:达到1 全面理解UML知识体系与项目中实际应用.设计模式撑握与项目中应用 第二个目标:两个月并行学习设计模式.UML.ROSE

【DAY18】Socket编程,ROSE建模与TCP/IP的学习笔记

IDE eclipse调试 ------------------ 1.Debug 2.Step into : F5  ,单步进入. 3.Step return : F7,单步返回. 4.Stop over : F6,单步跳过. 安装Rose建模软件 ----------------- 1.安装虚拟光驱软件:DTLite.exe 2.加载Rose镜像文件. 3.一路安装,next... 4.安装完成注册License. a.在license管理器界面 开始 --> IBM Rose -> Lic

Struts2学习总结(3)

本文包括以下五个部分: 值栈. Ognl表达式. struts2标签库. 国际化. 表单数据校验 拦截器. struts2的执行过程. 一.值栈 采用servlet和JSP开发时,servlet通过域对象保存数据,在JSP页面通过jstl标签+el表达式获取数据. 采用struts2和JSP框架进行开发时,Action通过值栈对象保存数据,在JSP页面通过struts标签+ognl表达式获取数据. 1.1 值栈(ValueStack)的概念 值栈就是存放action的堆栈,用来存储请求响应数据,

Gun N&#39; Rose Team Review

一看到这个项目就被他的功能给吸引了.回忆起以前看到一个东西很新奇想去网上查询它是什么,但是又不知道应该怎样去描述它,于是在搜索引擎的输入框中键入.删除.键入.删除的可笑经历的时候,我就越发感觉到这个app的必要性了.画出查询对象的大致轮廓,系统自动搜筛选出相似的图片,这个app实现了“所见即所得”,令人称赞. 当然,这个app也存在很多局限性,比如说它返回的图片数量很大,没能实现精确定位,如果能让用户在输入时添加对对象的模糊描述,比如说:不是房子,像苹果等无疑将提高搜索的准确度.另外,这个app

java学习路线及资源下载,持续整理中

java学习路线及资源下载,持续整理中 学习路线图:http://blog.csdn.net/shenzhq1980/article/details/484703371.java学习经典书籍_基础编程篇下载地址:http://blog.csdn.net/shenzhq1980/article/details/48375543书籍:Java程序设计语言.(美国)阿诺德.清晰版JAVA2核心技术第1卷.基础知识7thJAVA2核心技术卷II:高级特性7th Java语言程序设计-基础篇(原书第8版)

MySQl Study学习之--MySQl二进制日志管理

MySQl Study学习之--MySQl二进制日志管理 MySQL二进制日志(Binary Log):   a.它包含的内容及作用如下:    包含了所有更新了数据或者已经潜在更新了数据(比如没有匹配任何行的一个DELETE)    包含关于每个更新数据库(DML)的语句的执行时间信息    不包含没有修改任何数据的语句,如果需要启用该选项,需要开启通用日志功能    主要目的是尽可能的将数据库恢复到数据库故障点,因为二进制日志包含备份后进行的所有更新    用于在主复制服务器上记录所有将发送

UML学习笔记

这个学期有幸选到章老师的UML精品课程,虽然到目前仅仅上课两周,但是收益匪浅.尽管在本科接触过UML,却没有非常详细的对其进行深入的了解,只是对一些图的名称有所耳闻,没有深究其功能. 就最近所学知识,谈一下我对uml统一建模语言的一个总体认识,软件工程作为一门工程类学科,如同建筑类学科一样,当我们需要搭建一所建筑时,我们都需要对其进行需求和设计,在施工的时候,我们就需要一些设计图纸,例如各个房间的具体设计.三维视图等,通过这些图纸进行施工.软件工程也是如此,当我们拿到一个项目时,并不是直接开始编

MySQL学习笔记-数据类型与操作数据表

MySQL学习笔记-数据类型与操作数据表 数据类型:  1.字符型  2.整型  3.浮点型  4.日期时间型 数据表操作:  1.插入记录  2.查找记录 记录操作:  1.创建数据表  2.约束的使用 1.数据类型 [1]整型: 数据类型 存储范围 字节 TINYINT 有符号型:-128~127(-2^7~2^7 -1),无符号型0~255(0~2^8 -1) 1 SMALLINT 有符号型:-2^15~2^15 -1,无符号型0~2^16 -1 2 MEDIUMINT 有符号型:-2^2

python基础语法学习常见小问题

说明:我是最近觉得python在完成很多工作中方便使用而且功能强大,想突击学习一下.用的是廖雪峰老师的教程,学习python3.X.这里是廖雪峰老师的网站链接: http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000 本人用的windows学习python: 一.常见小的细节: 1.python中 elif 是else if的缩写: 2.python初始使用有交互式的,就是有>>>