littleQ

终于明白曾经他们失落的目光,当年的你们是否一样;间有懈怠或有颓放,难知多久方能补上;今起,不再彷徨!

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  33 Posts :: 0 Stories :: 60 Comments :: 0 Trackbacks
 Deploying the application

在我们运行Controller之前,必须对其进行编译。我们可以使用javac或者任何IDE去编译Controller。接下来,我们要让Tomcat知道我们的web应用程序。我们需要创建一个war包,然后部署到Tomcat中,这步只需要将war包拷贝到:/dev/Tomcat6/webapps目录下。

我们的.war文件中的/WEB-INF文件夹包含以下文件:

web.xml
induction-demoapp.xml

以下.jar文件在WEB-INF/lib:

acciente-induction-1.x.xb.jar
acciente-commons-1.x.xb.jar

最后,以下工具jar包也同样在WEB-INF/lib:

apache-bcel-5.2.jar
apache-commons-collections-3.2.1.jar
apache-commons-digester-1.8.jar
apache-commons-fileupload-1.2.1.jar
apache-commons-io-1.4.jar
apache-commons-logging-1.1.1.jar
apache-freemarker-2.3.12.jar

这些.jar文件分别来自于这些工程:Apache Commons库和Apache BCEL库来自Apache Software Foundation. Freemarker库源自Visigoth Software Society.

我们主意到应用程序类的代码(在这里,就是单个Controller)没有存储在.war文件中,相反,我们会在应用程序的配置文件induction-demoapp.xml中指明编译后.class文件的位置.不管我们什么时候重新编译一个应用程序类,下一次访问这个类的时候,Induction会检测出class文件发生了变化,然后"热部署"JVM.因此,当我们修改或者编译应用程序类的时候,没有必要去重新创建或者重新部署war.

Induction同样也支持将应用程序类放到.war/WEB-INF/classes,或者将.jar放到/WEB-INF/lib,或者Tomcat可以找到的classpath下的其他任何位置.不过在开发中,我们推荐将应用程序类放在war包外面,这样可以通过class"热重载"来提高生产率.如果有必要的话,应用程序类可以重新打包成.war文件用于传递.接下来,我们来看看war包里面的内容.

首先来看看web.xml.我们在web.xml中所需要做的就是定义Inductiondispatcher servlet去处理对应用程序的请求.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
          http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
           version="2.5">
   <description>DemoApp</description>

   <servlet>
       <servlet-name>demoapp</servlet-name>
       <servlet-class>com.acciente.induction.dispatcher.HttpDispatcher</servlet-class>
       <load-on-startup>1</load-on-startup>
   </servlet>

   <servlet-mapping>
       <servlet-name>demoapp</servlet-name>
       <url-pattern>/*</url-pattern>
   </servlet-mapping>
</web-app>

我们再来看看induction-demoapp.xml的内容.假设我们编译后的应用程序类是放在c:/project/demoapp/classes目录下,induction-demoapp.xml的内容就是:

<!-- this file contains the configuration for the Induction dispatcher -->
<config>
<!-- The following section allows you to specify locations from which
Induction will automatically reload a class if the file has changed -->
<java-class-path>
<compiled-directory>
<directory>c:/project/demoapp/classes</directory>
</compiled-directory>
</java-class-path>
</config>

创建好上面所描述的war包后,部署到Tomcat.现在,我们可以开始运行我们的应用程序了.

Running the application

假设Tomcat运行在localhost:8080,war包的名字是induction-demo.war,在浏览器中输入以下URL:

http://localhost:8080/induction-demo/demoapp/helloworld1_app/HelloWorldController/

你会在浏览器输出界面看到字符串:

Hello World, using a simple println()

Controlling the URL resolution

现在我们来进一步的看下用来运行ControllerURL:http://localhost:8080/induction-demo/demoapp/helloworld1_app/HelloWorldController/.第一部分http://localhost:8080/induction-demo通过Tomcat指向dispatcher servlet,也就是说这一部分是与Induction无关的.通过Induction处理的URL部分是/demoapp/helloworld1_app/HelloWorldController/.

InductionURL分解成完整的Controller类和方法名.URL转换成Controller的类名和方法名,是通过InductionControllerResolver类口完成的.当开发者没有指定一个定制的Controller resolver,Induction会默认使用一个相当简单的controller resolver.默认的controller resolver是这么工作的:分析路径/demoapp/helloworld1_app/HelloWorldController/,把第一个'/'到最后一个'/'之间的内容作为完整的类名(/demoapp/helloworld1_app/HelloWorldController/就是对应到demoapp.helloworld1_app.HelloWorldController).最后一个'/'后所有的内容作为方法名.在我们的例子中,最后一个'/'后没有任何字符串,因此默认的resolver会使用一个隐性的方法名(默认的resolver使用"handler"作为隐性的方法名,不过可以在Induction的配置文件中进行修改).

Dynamic reloading

我们来找点乐子,修改一下controller中打印的字符串的值,编译后重新刷新你的浏览器,你会发现修改起了作用.不必再经过"创建war->重新部署->等待"的过程了.

Conclusion

总结一下我们的指南.在指南中,我们讨论了一些关键的思想,在接下来的view Tutorial中会介绍在Induction中如何使用views.Modles会在Modles Tutorial中进行介绍.

posted on 2008-07-31 22:17 littleQ 阅读(1088) 评论(4)  编辑  收藏 所属分类: induction

Feedback

# re: Getting Started with Induction-翻译(2) 2008-08-01 02:01 酒店咨询
hehe,辛苦你了  回复  更多评论
  

# re: Getting Started with Induction-翻译(2) 2008-08-01 15:57 残梦追月
myeclispe的帮助文档?  回复  更多评论
  

# re: Getting Started with Induction-翻译(2) 2008-08-01 15:57 残梦追月
还是tomcat的帮助文档?……  回复  更多评论
  

# re: Getting Started with Induction-翻译(2) 2008-08-01 16:35 littleQ
@残梦追月
恩?都不是……  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: