由于楼主是windows平台,所以mac的朋友们请看官方安装步骤哟。https://www.playframework.com/documentation/2.2.x/Installing
pre1:jdk6+的版本http://www.oracle.com/technetwork/java/javase/downloads/index.html
pre2:eclispe版本下载:http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/marsr
1.到https://downloads.typesafe.com/play/2.2.6/play-2.2.6.zip下载play 2.2.6安装包。
2.解压zip到xx目录,得到xx\play-2.2.6 的目录。设置环境变量
点击计算机 - 属性
2.点击高级系统设置
3.点击环境变量
4.点击新建
5.设置环境变量,注意不要加“;”
6.找到Path,点击编辑
7.输入";%PLAY%;"注意分号。
8.验证Path&Play
1. play new [direaction]
调出CMD输入 play new myNews //默认为当前路径,
要是想创建到其他路径,需要写入全路径比如:E:\workspace-main\j2ee\myNews
2.输入application name,这里同样输入myNews
3.输入2(“ 2 - Create a simple Java application”)
4.创建完毕。
app → Application sources └ assets → Compiled asset sources └ stylesheets → Typically LESS CSS sources └ javascripts → Typically CoffeeScript sources └ controllers → Application controllers └ models → Application business layer └ views → Templates build.sbt → Application build script conf → Configurations files and other non-compiled resources (on classpath) └ application.conf → Main configuration file └ routes → Routes definition public → Public assets └ stylesheets → CSS files └ javascripts → Javascript files └ images → Image files project → sbt configuration files └ build.properties → Marker for sbt project └ plugins.sbt → sbt plugins including the declaration for Play itself lib → Unmanaged libraries dependencies logs → Standard logs folder └ application.log → Default log file target → Generated stuff └ scala-2.10.0 └ cache └ classes → Compiled class files └ classes_managed → Managed class files (templates, ...) └ resource_managed → Managed resources (less, ...) └ src_managed → Generated sources (templates, ...) test → source folder for unit or functional tests
1.打开cmd,cd到创建项目的目录下
2.输入 play,初始化项目,等到出现"[myNews] $"就OK了。
3.输入 run,就开始解析资源,然后启动9000的端口了。输入http://localhost:9000/就可以访问myNews了
第一次貌似访问有点慢,貌似在编译一些东西。(红框的部分是第一次访问参数的日志)
4.输入ctrl+d 停止web application的运行。
1.打开cmd ,cd到创建的工程myNews。
2.输入eclipse
打开刚才的工作空间发现,产生了如下文件:
3.打开eclispe,导入myNews,发现工程如下,发现引用的lib太多了,稍后我们滴4步优化下。
4.在eclipse,打开window,选中prefence,依次展开Java->Build Path->User Libraries,点击右边的New,输入PLAY_LIBS点击OK。
5.在%eclips_workspace%\.metadata\.plugins\org.eclipse.core.runtime\.settings
%eclips_workspace%代表你的工作空间。比如我的是E:\workspace-main\j2ee
那么我的路径就是:E:\workspace-main\j2ee\.metadata\.plugins\org.eclipse.core.runtime\.settings
找到并打开“org.eclipse.jdt.core.prefs”
末尾添加:
org.eclipse.jdt.core.userLibrary.PLAY_LIBS=<?xml version\="1.0" encoding\="UTF-8"?>\r\n<userlibrary systemlibrary\="false" version\="2">\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.typesafe.play/play-java-jdbc_2.10/2.2.6/jars/play-java-jdbc_2.10.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.typesafe.play/play-jdbc_2.10/2.2.6/jars/play-jdbc_2.10.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.typesafe.play/play_2.10/2.2.6/jars/play_2.10.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.typesafe.play/sbt-link/2.2.6/jars/sbt-link.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.javassist/javassist/3.18.0-GA/bundles/javassist.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.typesafe.play/play-exceptions/2.2.6/jars/play-exceptions.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.typesafe.play/templates_2.10/2.2.6/jars/templates_2.10.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.github.scala-incubator.io/scala-io-file_2.10/0.4.2/jars/scala-io-file_2.10.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.github.scala-incubator.io/scala-io-core_2.10/0.4.2/jars/scala-io-core_2.10.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.jsuereth/scala-arm_2.10/1.3/jars/scala-arm_2.10.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.typesafe.play/play-iteratees_2.10/2.2.6/jars/play-iteratees_2.10.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.scala-stm/scala-stm_2.10/0.7/jars/scala-stm_2.10.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.typesafe/config/1.0.2/bundles/config.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.typesafe.play/play-json_2.10/2.2.6/jars/play-json_2.10.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.typesafe.play/play-functional_2.10/2.2.6/jars/play-functional_2.10.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.typesafe.play/play-datacommons_2.10/2.2.6/jars/play-datacommons_2.10.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/joda-time/joda-time/2.2/jars/joda-time.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.joda/joda-convert/1.3.1/jars/joda-convert.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.fasterxml.jackson.core/jackson-annotations/2.2.2/jars/jackson-annotations.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.fasterxml.jackson.core/jackson-core/2.2.2/jars/jackson-core.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.fasterxml.jackson.core/jackson-databind/2.2.2/jars/jackson-databind.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/io.netty/netty/3.7.1.Final/bundles/netty.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.typesafe.netty/netty-http-pipelining/1.1.2/jars/netty-http-pipelining.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.slf4j/slf4j-api/1.7.5/jars/slf4j-api.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.slf4j/jul-to-slf4j/1.7.5/jars/jul-to-slf4j.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.slf4j/jcl-over-slf4j/1.7.5/jars/jcl-over-slf4j.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/ch.qos.logback/logback-core/1.0.13/jars/logback-core.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/ch.qos.logback/logback-classic/1.0.13/jars/logback-classic.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.typesafe.akka/akka-actor_2.10/2.2.0/jars/akka-actor_2.10.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.typesafe.akka/akka-slf4j_2.10/2.2.0/bundles/akka-slf4j_2.10.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.apache.commons/commons-lang3/3.1/jars/commons-lang3.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.ning/async-http-client/1.7.18/jars/async-http-client.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/oauth.signpost/signpost-core/1.2.1.2/jars/signpost-core.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/oauth.signpost/signpost-commonshttp4/1.2.1.2/jars/signpost-commonshttp4.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/commons-logging/commons-logging/1.1.1/jars/commons-logging.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/xerces/xercesImpl/2.11.0/jars/xercesImpl.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/xml-apis/xml-apis/1.4.01/jars/xml-apis.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/javax.transaction/jta/1.1/jars/jta.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.jolbox/bonecp/0.8.0.RELEASE/bundles/bonecp.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.google.guava/guava/14.0.1/bundles/guava.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.h2database/h2/1.3.172/jars/h2.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/tyrex/tyrex/1.0.1/jars/tyrex.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.typesafe.play/play-java_2.10/2.2.6/jars/play-java_2.10.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.yaml/snakeyaml/1.12/bundles/snakeyaml.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.hibernate/hibernate-validator/5.0.1.Final/jars/hibernate-validator.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/javax.validation/validation-api/1.1.0.Final/jars/validation-api.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.jboss.logging/jboss-logging/3.1.1.GA/jars/jboss-logging.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.fasterxml/classmate/0.8.0/bundles/classmate.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.springframework/spring-context/3.2.3.RELEASE/jars/spring-context.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.springframework/spring-core/3.2.3.RELEASE/jars/spring-core.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.springframework/spring-beans/3.2.3.RELEASE/jars/spring-beans.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.reflections/reflections/0.9.8/jars/reflections.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.google.code.findbugs/jsr305/2.0.1/jars/jsr305.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/javax.servlet/javax.servlet-api/3.0.1/jars/javax.servlet-api.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.typesafe.play/play-java-ebean_2.10/2.2.6/jars/play-java-ebean_2.10.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.avaje.ebeanorm/avaje-ebeanorm/3.2.2/jars/avaje-ebeanorm.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.avaje.ebeanorm/avaje-ebeanorm-agent/3.2.1/jars/avaje-ebeanorm-agent.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.hibernate.javax.persistence/hibernate-jpa-2.0-api/1.0.1.Final/jars/hibernate-jpa-2.0-api.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.typesafe.play/play-cache_2.10/2.2.6/jars/play-cache_2.10.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/net.sf.ehcache/ehcache-core/2.6.6/jars/ehcache-core.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.typesafe.play/play-test_2.10/2.2.6/jars/play-test_2.10.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/junit/junit/4.11/jars/junit.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.hamcrest/hamcrest-core/1.3/jars/hamcrest-core.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.specs2/specs2_2.10/2.1.1/jars/specs2_2.10.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.scalaz/scalaz-core_2.10/7.0.2/bundles/scalaz-core_2.10.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.scalaz/scalaz-concurrent_2.10/7.0.2/bundles/scalaz-concurrent_2.10.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.scalaz/scalaz-effect_2.10/7.0.2/bundles/scalaz-effect_2.10.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/com.novocode/junit-interface/0.10/jars/junit-interface.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.scala-tools.testing/test-interface/0.5/jars/test-interface.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.fluentlenium/fluentlenium-festassert/0.8.0/jars/fluentlenium-festassert.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.fluentlenium/fluentlenium-core/0.8.0/jars/fluentlenium-core.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.seleniumhq.selenium/selenium-java/2.32.0/jars/selenium-java.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.seleniumhq.selenium/selenium-android-driver/2.32.0/jars/selenium-android-driver.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.seleniumhq.selenium/selenium-remote-driver/2.32.0/jars/selenium-remote-driver.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/cglib/cglib-nodep/2.1_3/jars/cglib-nodep.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.json/json/20080701/jars/json.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.seleniumhq.selenium/selenium-api/2.32.0/jars/selenium-api.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.apache.httpcomponents/httpclient/4.2.1/jars/httpclient.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.apache.httpcomponents/httpcore/4.2.1/jars/httpcore.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/commons-codec/commons-codec/1.6/jars/commons-codec.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.apache.commons/commons-exec/1.1/jars/commons-exec.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/net.java.dev.jna/jna/3.4.0/jars/jna.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/net.java.dev.jna/platform/3.4.0/jars/platform.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.seleniumhq.selenium/selenium-chrome-driver/2.32.0/jars/selenium-chrome-driver.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.seleniumhq.selenium/selenium-htmlunit-driver/2.32.0/jars/selenium-htmlunit-driver.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/net.sourceforge.htmlunit/htmlunit/2.12/jars/htmlunit.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/xalan/xalan/2.7.1/jars/xalan.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/xalan/serializer/2.7.1/jars/serializer.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/commons-collections/commons-collections/3.2.1/jars/commons-collections.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.apache.httpcomponents/httpmime/4.2.3/jars/httpmime.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/net.sourceforge.htmlunit/htmlunit-core-js/2.12/jars/htmlunit-core-js.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/net.sourceforge.nekohtml/nekohtml/1.9.18/jars/nekohtml.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/net.sourceforge.cssparser/cssparser/0.9.9/jars/cssparser.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.w3c.css/sac/1.3/jars/sac.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/commons-io/commons-io/2.2/jars/commons-io.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.eclipse.jetty/jetty-websocket/8.1.9.v20130131/jars/jetty-websocket.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.eclipse.jetty/jetty-util/8.1.9.v20130131/jars/jetty-util.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.eclipse.jetty/jetty-io/8.1.9.v20130131/jars/jetty-io.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.eclipse.jetty/jetty-http/8.1.9.v20130131/jars/jetty-http.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.seleniumhq.selenium/selenium-firefox-driver/2.32.0/jars/selenium-firefox-driver.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.seleniumhq.selenium/selenium-ie-driver/2.32.0/jars/selenium-ie-driver.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.seleniumhq.selenium/selenium-iphone-driver/2.32.0/jars/selenium-iphone-driver.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.seleniumhq.selenium/selenium-safari-driver/2.32.0/jars/selenium-safari-driver.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.webbitserver/webbit/0.4.14/jars/webbit.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.seleniumhq.selenium/selenium-support/2.32.0/jars/selenium-support.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.easytesting/fest-assert/1.4/jars/fest-assert.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/repository/local/org.easytesting/fest-util/1.1.6/jars/fest-util.jar"/>\r\n\t<archive path\="E\:/IDE-OTHRE/play-2.2.6/framework/sbt/boot/scala-2.10.3/lib/scala-library.jar"/>\r\n</userlibrary>\r\n
如果你的play路径不是“E:\IDE-OTHRE\play-2.2.6”你需要添加如下替换假设你的路径是X:Y\Z:
那么需要全部替换"X\:/Y/Z",此处注意盘符后有个\,并且替换的时候不需要选择正则表达式匹配
最终效果是这个样子:
6.重新打开Eclipse,点击myNews右键Build Path -> Configure Build Path ,选中所以的LIB,remove
7.在6的基础上,点击 Add Libraries,选中User Library,选择我们刚才新建的“PLAY_LIBS”,点击OK
8.点击myNews右键Build Path -> Configure Build Path ,点击Add Class Folder,
选择myNews/target/scale-2.0/classes_managed,点击OK
9.build 该项目。不会报错就成了了
过程比较繁琐,也不知道有更好的方式没有,如有的话,请道友指点下。