play framework 从环境搭建到简单运行
download
官网:https://www.playframework.com/
将zip下载至本地,进行unzip。
环境变量
检测是否安装成功:解压成功后进入解压的目录,运行
play
终端显示
zsh: command not found: play
需要配置环境变量
mac /linux:
zsh:
vi ~/.zshrc
添加如下配置
export PLAY_HOME=/Users/leesin/Downloads/play-1.4.3
export PATH=$PATH:$PLAY_HOME
bash:
vi ~/.bash_profile
添加如下配置
export PLAY_HOME=/Users/leesin/Downloads/play-1.4.3
export PATH=$PATH:$PLAY_HOME
windows略
然后执行
➜ play-1.4.3 play
~ _ _
~ _ __ | | __ _ _ _| |
~ | '_ \| |/ _' | || |_|
~ | __/|_|\____|\__ (_)
~ |_| |__/
~
~ play! 1.4.3, https://www.playframework.com
~
~ Usage: play cmd [app_path] [--options]
~
~ with, new Create a new application
~ run Run the application in the current shell
~ help Show play help
说明成功了。
启动
创建一个项目,这个项目的地址在 play-1.4.3目录下
➜ play-1.4.3 play new leesin
~ _ _
~ _ __ | | __ _ _ _| |
~ | '_ \| |/ _' | || |_|
~ | __/|_|\____|\__ (_)
~ |_| |__/
~
~ play! 1.4.3, https://www.playframework.com
~
~ The new application will be created in /Users/leesin/Downloads/play-1.4.3/leesin
~ What is the application name? [leesin] leesin
~
~ OK, the application is created.
~ Start it with : play run leesin
~ Have fun!
~
运行项目:
➜ play-1.4.3 play run leesin
~ _ _
~ _ __ | | __ _ _ _| |
~ | '_ \| |/ _' | || |_|
~ | __/|_|\____|\__ (_)
~ |_| |__/
~
~ play! 1.4.3, https://www.playframework.com
~
~ Ctrl+C to stop
~
~ using java version "1.7.0_60"
objc[57175]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/bin/java (0x10bebb4c0) and /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10bf684e0). One of the two will be used. Which one is undefined.
Listening for transport dt_socket at address: 8000
11:06:15,185 INFO ~ Starting /Users/leesin/Downloads/play-1.4.3/leesin
浏览器访问:
loaclahost:9000
转化成能导入eclipse idea的项目
执行
play eclipse
然后导入即可
play-1.4.3错误
java.lang.RuntimeException: Need to restart Play because /Users/leesin/Downloads/play-1.4.3/leesin/conf/application.conf has been changed
at play.ConfigurationChangeWatcherPlugin.onConfigurationFileChanged(ConfigurationChangeWatcherPlugin.java:30)
at play.ConfigurationChangeWatcherPlugin.detectChange(ConfigurationChangeWatcherPlugin.java:24)
at play.plugins.PluginCollection.detectChange(PluginCollection.java:598)
at play.Play.detectChanges(Play.java:641)
at play.Invoker$Invocation.init(Invoker.java:199)
at Invocation.HTTP Request(Play!)
11:06:36,412 INFO ~ Application 'leesin' is now started !
这个问题已经在1.4.4中得到了修复。