play 介绍

来源:互联网 发布:搜狐快站 seo 编辑:程序博客网 时间:2024/04/28 17:15

,# play 介绍

  Play作为web容器,相当于struts+ibatis+页面,都涉及到。启动的方式也是有几种,可以采用tomcat方式进行启动,也可以用play项目自带的test.launch来启动(默认端口号是9000,这个主要是基于mina来实现通信的).  优点: 1) 编译java文件。刷新浏览器无需重启服务        2) 基于hibernate,Memcached等插件        3) 非阻塞io模型,允许基于长轮询和websockedts的web应用
  1. 先看下如何建立一个play 项目
    1) 下载jar包 http://downloads.typesafe.com/play/1.2.7/play-1.2.7.zip
    官方网站是:http://www.playframework.com
    2) 配置环境变量 Path = D:\paly-1.2.7
    3) cmd- >play 查看是否安装成功
    4) play new Test cases : 创建Test cases项目
    play eclipsify Test cases
    将Test cases 导入到eclipse 中,右键运行Test cases.launch。在浏览器输入http://localhost:9000
  // test.launch文件    <?xml version="1.0" encoding="UTF-8"?><launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">    <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">        <listEntry value="/test"/>    </listAttribute>    <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">        <listEntry value="4"/>    </listAttribute>    <booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>    <listAttribute key="org.eclipse.jdt.launching.CLASSPATH">        <listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;runtimeClasspathEntry containerPath=&quot;org.eclipse.jdt.launching.JRE_CONTAINER&quot; javaProject=&quot;test&quot; path=&quot;1&quot; type=&quot;4&quot;/&gt;&#10;"/>        <listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;runtimeClasspathEntry internalArchive=&quot;/test/conf&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#10;"/>        <listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;runtimeClasspathEntry externalArchive=&quot;E:\play-1.2.7/modules/testrunner/lib/play-testrunner.jar&quot; path=&quot;3&quot; type=&quot;2&quot;/&gt;&#13;&#10;"/>        <listEntry value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#10;&lt;runtimeClasspathEntry id=&quot;org.eclipse.jdt.launching.classpathentry.defaultClasspath&quot;&gt;&#10;&lt;memento exportedEntriesOnly=&quot;false&quot; project=&quot;test&quot;/&gt;&#10;&lt;/runtimeClasspathEntry&gt;&#10;"/>    </listAttribute>    <booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>    <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="play.server.Server"/>    <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="test"/>    <stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx512m -Xms512m -XX:PermSize=256m -XX:MaxPermSize=512m -Xdebug -Dplay.debug=yes -Dplay.id= -Dapplication.path=&quot;${project_loc:test}&quot; -Djava.endorsed.dirs=&quot;E:\play-1.2.7/framework/endorsed&quot; -javaagent:&quot;E:\play-1.2.7/framework/play-1.2.7.jar&quot;"/></launchConfiguration>
  1. 来利用maven 来查看play 源代码
    1) 下载maven包并且解压 http://apache.fayea.com/maven/maven-3/3.1.1/binaries/apache-maven-3.1.1-bin.zip
    2) 环境变量
    maven_home=C:\Program Files\Java\apache-maven-3.1.1
    path变量末尾增加:%maven_home%\bin
    检查是否安装成功:在CMD中输入mvn,看是否识别该命令
    3)I) 用play命令来创建
    进入到已经创建好的play目录下eg: cd C:\Test cases
    play install maven
    对于已经存在的工程,在conf/application.conf中加入以下内容 module.maven=${play.path}/modules/maven-head
    play mvn:init 命令在工程目录下自动生成pom.xml文件,然后将需要依赖的dependency 加入pom.xml文件即可(需要添加对应的repositories)
    play mvn:update 或者 play mvn:up 会获取定义的依赖,并将其放在app/lib下面
    play mvn:re 刷新依赖包
    play mvn:src 这里的操作是获取源码包的jar包。source包从maven中央仓库同步到maven本地仓库。
    II) maven命令来实现
    新建个项目
    play new Test cases
    play eclipsify Test cases
    然后导入eclipse中,右键configuer->转变成maven项目
    修改pom.xml。
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  <modelVersion>4.0.0</modelVersion>  <groupId>tour</groupId>  <artifactId>tour</artifactId>  <version>0.0.1-SNAPSHOT</version> <dependencies>            <dependency>                <groupId>javax.activation</groupId>                <artifactId>activation</artifactId>                <version>1.1.1</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>antlr</groupId>                <artifactId>antlr</artifactId>                <version>2.7.6</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>com.ning</groupId>                <artifactId>async-http-client</artifactId>                <version>1.2.0</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>org.bouncycastle</groupId>                <artifactId>bcprov-jdk15</artifactId>                <version>1.45</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>c3p0</groupId>                <artifactId>c3p0</artifactId>                <version>0.9.1.2</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>cglib</groupId>                <artifactId>cglib-nodep</artifactId>                <version>2.2</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>commons-beanutils</groupId>                <artifactId>commons-beanutils</artifactId>                <version>1.8.3</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>commons-codec</groupId>                <artifactId>commons-codec</artifactId>                <version>1.4</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>commons-collections</groupId>                <artifactId>commons-collections</artifactId>                <version>3.1</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>org.apache.commons</groupId>                <artifactId>commons-email</artifactId>                <version>1.2</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>commons-fileupload</groupId>                <artifactId>commons-fileupload</artifactId>                <version>1.2</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>commons-io</groupId>                <artifactId>commons-io</artifactId>                <version>1.4</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>commons-lang</groupId>                <artifactId>commons-lang</artifactId>                <version>2.5</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>commons-logging</groupId>                <artifactId>commons-logging</artifactId>                <version>1.1.1</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>dom4j</groupId>                <artifactId>dom4j</artifactId>                <version>1.6.1</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>net.sf.ehcache</groupId>                <artifactId>ehcache-core</artifactId>                <version>2.0.0</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>net.sf.ezmorph</groupId>                <artifactId>ezmorph</artifactId>                <version>1.0.3</version>                <scope>provided</scope>            </dependency><!--            <dependency> --><!--                <groupId>org.codehaus.groovy</groupId> --><!--                <artifactId>groovy-all</artifactId> --><!--                <version>1.7.1</version> --><!--                <scope>provided</scope> --><!--            </dependency> -->            <dependency>                <groupId>com.google.code.gson</groupId>                <artifactId>gson</artifactId>                <version>1.4</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>org.hibernate</groupId>                <artifactId>hibernate-core</artifactId>                <version>3.5.6-Final</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>org.hibernate</groupId>                <artifactId>hibernate-annotations</artifactId>                <version>3.5.6-Final</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>org.hibernate</groupId>                <artifactId>hibernate-commons-annotations</artifactId>                <version>3.2.0.Final</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>org.hibernate</groupId>                <artifactId>hibernate-entitymanager</artifactId>                <version>3.5.6-Final</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>org.hibernate.javax.persistence</groupId>                <artifactId>hibernate-jpa-2.0-api</artifactId>                <version>1.0.0.Final</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>javax.mail</groupId>                <artifactId>mail</artifactId>                <version>1.4.3</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>javassist</groupId>                <artifactId>javassist</artifactId>                <version>3.9.0.GA</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>jaxen</groupId>                <artifactId>jaxen</artifactId>                <version>1.1</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>joda-time</groupId>                <artifactId>joda-time</artifactId>                <version>1.6</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>net.sf.jsr107cache</groupId>                <artifactId>jsr107cache</artifactId>                <version>1.0</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>javax.transaction</groupId>                <artifactId>jta</artifactId>                <version>1.1</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>junit</groupId>                <artifactId>junit</artifactId>                <version>4.8.1</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>log4j</groupId>                <artifactId>log4j</artifactId>                <version>1.2.16</version>                <scope>provided</scope>            </dependency>            <!-- This lib must be added to your repository -->            <dependency>                <groupId>mysql</groupId>                <artifactId>mysql-connector-java</artifactId>                <version>5.1.13</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>org.jboss.netty</groupId>                <artifactId>netty</artifactId>                <version>3.2.2.Final</version>                <scope>provided</scope>            </dependency>            <!-- This lib must be added to your repository -->            <dependency>                <groupId>net.sf.oval</groupId>                <artifactId>oval</artifactId>                <version>1.50</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>org.apache.geronimo.specs</groupId>                <artifactId>geronimo-servlet_2.5_spec</artifactId>                <version>1.2</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>oauth.signpost</groupId>                <artifactId>signpost-core</artifactId>                <version>1.2</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>org.slf4j</groupId>                <artifactId>slf4j-api</artifactId>                <version>1.6.1</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>org.slf4j</groupId>                <artifactId>slf4j-log4j12</artifactId>                <version>1.6.1</version>                <scope>provided</scope>            </dependency>            <dependency>                <groupId>org.yaml</groupId>                <artifactId>snakeyaml</artifactId>                <version>1.6</version>                <scope>provided</scope>            </dependency><dependency>    <groupId>io.netty</groupId>    <artifactId>netty-all</artifactId>    <version>4.1.8.Final</version></dependency>    <dependency>      <groupId>commons-logging</groupId>      <artifactId>commons-logging</artifactId>      <version>1.1.3</version>    </dependency>    <dependency>      <groupId>io.protostuff</groupId>      <artifactId>protostuff-core</artifactId>      <version>1.3.5</version>    </dependency>    <dependency>      <groupId>io.protostuff</groupId>      <artifactId>protostuff-runtime</artifactId>      <version>1.3.5</version>    </dependency>    <dependency>      <groupId>com.caucho</groupId>      <artifactId>hessian</artifactId>      <version>4.0.38</version>    </dependency>    <dependency>            <groupId>dom4j</groupId>            <artifactId>dom4j</artifactId>            <version>1.6.1</version>        </dependency>        <dependency>            <groupId>jaxen</groupId>            <artifactId>jaxen</artifactId>            <version>1.1.6</version>        </dependency>        <dependency>            <groupId>log4j</groupId>            <artifactId>log4j</artifactId>            <version>1.2.16</version>        </dependency>        <dependency>            <groupId>junit</groupId>            <artifactId>junit</artifactId>            <version>4.9</version>            <scope>test</scope>        </dependency>            <!-- Play! framework dependency -->        </dependencies>  <build>    <sourceDirectory>app</sourceDirectory>    <testSourceDirectory>test</testSourceDirectory>    <resources>      <resource>        <directory>app</directory>        <excludes>          <exclude>**/*.java</exclude>        </excludes>      </resource>    </resources>    <testResources>      <testResource>        <directory>test</directory>        <excludes>          <exclude>**/*.java</exclude>        </excludes>      </testResource>    </testResources>    <plugins>      <plugin>        <artifactId>maven-compiler-plugin</artifactId>        <version>3.1</version>        <configuration>          <source/>          <target/>        </configuration>      </plugin>    </plugins>  </build></project>

把依赖的jar包都删掉,除了pay-1.12.jar
cmd 项目所在的位置
mvn dependency:sources 下载源代码
2. 部署项目到tomcat下
cmd C:\Test cases
play war –exclude .svn:logs:tmp:db -o E:\war2131 生成war包
将这个包放入到E:\清理\tomcat\t1\webapps\ROOT ,tomcat下。重启tomcat即可

附加一个添加java的源码,也就是rt.jar

  1. 打开eclipse,点 “window”-> “Preferences” -> “Java” -> “Installed JRES”
  2. 此时”Installed JRES”右边是列表窗格,列出了系统中的 JRE 环境,选择你的JRE,然后点边上的 “Edit…”, 会出现一个窗口(Edit JRE)
  3. 选中rt.jar文件的这一项:“c:\program files\java\jre_1.5.0_06\lib\rt.jar” 点 左边的“+” 号展开它
  4. 展开后,可以看到“Source Attachment:(none)”,点这一项,点右边的按钮“Source Attachment…”, 选择你的JDK目录下的 “src.zip”文件

maven 仓库地址: http://repo.maven.apache.org/maven2/

根据jar来搜索所在maven仓库的地址http://mvnrepository.com/artifact/org.sonatype.tycho/org.eclipse.jdt.core/3.6.0.v_A48

所有的jar和源代码都是从maven仓库中下载的

0 0
原创粉丝点击