您的位置:首页 > 其它

play framework 2.5.3 学习和使用过程中的“坑”

2016-05-12 19:20 267 查看
play framework 2.5.3学习和使用过程中的“坑”

最近项目需要,接触到了play, 使用过程中,遇到了一些坑, 记下来。

1. 版本
play分1.x和2.x
两个系列,差异很大。

2.x系列 中的2.3+也有所不同,(目前官方的说法是
Lightbend Activator

安装还是比较简单的,
基本就是解压缩, 配置PATH

依赖的有
SCALA (基本也是解压缩,配置PATH)

2. jdk
文档上明确说明需要
java 1.8

我这边因为防火墙和
Linux 版本的问题, yum一直有问题。

这次的解决办法是,直接下载了Oracle的jdk1.8,tar.gz
版本的那个。

解压缩后,直接修改
/usr/bin/java 和/usr/bin/javac
的指向,(其他的没有动,可能会出现莫名错误)
修改了 /etc/profile中的
JAVA_HOME(没有的话, 创建一个)

3. 最基本的三个命令
第一次运行的时候,会自动下载很多的依赖项。需要耐心等候。
输出类似如下:

[info] Resolving jline#jline;2.12.1...
[info] downloadinghttps://repo1.maven.org/maven2/com/typesafe/play/play-server_2.11/2.5.0/play-server_2.11-2.5.0.jar...
[info] [SUCCESSFUL ]com.typesafe.play#play-server_2.11;2.5.0!play-server_2.11.jar(9245ms)
[info] downloadinghttps://repo1.maven.org/maven2/com/typesafe/play/play-java_2.11/2.5.0/play-java_2.11-2.5.0.jar...
[info] [SUCCESSFUL ]com.typesafe.play#play-java_2.11;2.5.0!play-java_2.11.jar (18457ms)
[info] downloadinghttps://repo1.maven.org/maven2/com/typesafe/play/play-netty-server_2.11/2.5.0/play-netty-server_2.11-2.5.0.jar...
[info] [SUCCESSFUL ]com.typesafe.play#play-netty-server_2.11;2.5.0!play-netty-server_2.11.jar(6129ms)

首先,安装好了后, 先得创建一个最小示例, 检验下还有哪些问题。
activator new mytest play-java,
使用play-java模板 创建
mytest工程
下面这个命令,省略了 模板
play-java, 可以交互的输入,如果也省略了项目名字,也可以交互输入

activator new test

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

Fetching the latest list oftemplates...

Could not fetch the updated list oftemplates. Using the local cache.
Check your proxy settings or increasethe timeout. For more details see: http://lightbend.com/activator/docs
Browse the list of templates:http://lightbend.com/activator/templates
Choose from these featured templates orenter a template name:
1) minimal-akka-java-seed
2) minimal-akka-scala-seed
3) minimal-java
4) minimal-scala
5) play-java
6) play-scala
(hit tab to see a list of alltemplates)
> 5 <=(输入5)

OK, application "test" isbeing created using the "play-java" template.
(省略部分输出)

To run "test" from thecommand line, "cd test" then:
/home/spark/activator-dist-1.3.10/test/activatorrun

To run the test for "test"from the command line, "cd test" then:
/home/spark/activator-dist-1.3.10/test/activatortest

To run the Activator UI for "test"from the command line, "cd test" then:
/home/spark/activator-dist-1.3.10/test/activatorui

[root@xuyongshi activator-dist-1.3.10]#
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

进入交互输入界面,或者控制台,

可以输入
compile 编译项目
run 运行在一个web容器里运行项目
test 单元测试

项目的名字,就是所在的文件夹, 这个文件夹的名字,以后可以修改,不会影响项目。

部分输出
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
[mytest] $ compile
[info] Updating{file:/tmp/mytest/}root...
[info] Resolving jline#jline;2.12.1...
[info] Done updating.
[info] Compiling 6 Scala sources and 10Java sources to /tmp/mytest/target/scala-2.11/classes...
[info] 'compiler-interface' not yetcompiled for Scala 2.11.7. Compiling...
[info] Compilation completed in29.644 s
[success] Total time: 94 s, completedMay 12, 2016 6:23:53 PM
[mytest] $ run

--- (Running the application,auto-reloading is enabled) ---

[error] p.c.s.NettyServer - Failed tolisten for HTTP on /0.0.0.0:9000!
[error] (compile:run)play.runsupport.ServerStartException
[error] Total time: 7 s, completed May12, 2016 6:24:03 PM
[mytest] $
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: