$ View.html.index cannot be resolved to a type
$ activator clean compile eclipse
$ View.html.index cannot be resolved to a type
$ activator clean compile eclipse
$ activator stopProd
$ kill $(cat target/universal/stage/RUNNING_PID)
$ dist
$ universal:packageZipTarball
$ path/to/hellow-world/bin/hello-world-app
[info] play.api.Play - Application started (Prod)
[info] p.c.s.NettyServer - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
$ chmod +x /path/to/bin/project-name
$ sudo nohup target/universal/stage/bin/eqa-app -Dhttp.port=80 -Dplay.crypto.secret="secret_token_123" /dev/null 2>&1 &
## Secret key
# http://www.playframework.com/documentation/latest/ApplicationSecret
# ~~~~~
# The secret key is used to sign Play's session cookie.
# This must be changed for production, but we don't recommend you change it in this file.
play.crypto.secret = "changeme"
/path/to/hello-world -Dplay.crypto.secret="secret_token_123"
play.crypto.secret="changeme"
play.crypto.secret=${?APPLICATION_SECRET}
include "application"
play.crypto.secret="QCY?tAnfk?aZ?iwrNwnxIlR6CTf:G3gf:90Latabg@5241AB`R5W:1uDFN];Ik@n"
/path/to/hello-word/bin/yourapp -Dconfig.file=/path/to/production.conf
$ playGenerateSecret
[info] Generated new secret: G28Dze]Z4lr@Or_9DCoz;tT_yCj6opKkkIh27K>[0l_NT9lZaFfs?=zx[Wulz>cX
[success] Total time: 0 s, completed Jan 11, 2017 6:24:12 PM
$ playUpdateSecret
[info] Generated new secret: QmJ?udauJgDj34AYifbprJvbT5I8^Vw1MY0WmbYRscZmAOotkalbhXbIs^48_Uc9
[info] Updating application secret in /Users/dpa/git/eqa-app/conf/application.conf
[info] Replacing old application secret: changeme
[success] Total time: 0 s, completed Jan 11, 2017 9:22:06 PM
We are going to check how Play connect http requests with our code. F.x. when user hits http://localhost:9000/ what happens?
There is already built in http router in Play Framework. It allows to connect incoming requests with Play Action and therefore with public method in a controller class.
Normally the configuration for HTTP routing is located in conf/routes. See example:
# Static path
GET /clients/all controllers.Clients.list()
# Dynamic path
GET /clients/:id controllers.Clients.show(id: Long)
GET /files/*name controllers.Application.download(name)
# Dynamic parts with regexp
GET /items/$id<[0-9]+> controllers.Items.show(id: Long)
If there are few routes are matched for the same request then the first one in a configuration file will be used.
Requests that come to application based on Play usually are processed by thing which is called action.
Action it is just a method that processes parameters of requests and sends result back to web client
Let's look on example below
package controllers;
import play.mvc.*;
/**
* This controller contains an action to handle HTTP requests
* to the application's home page.
*/
public class HomeController extends Controller {
/**
* An action that renders an HTML page with a welcome message.
* The configuration in the routes
file means that
* this method will be called when the application receives a
* GET
request with a path of /
.
*/
public Result index() {
return ok("Hello World!");
}
}
We see an action index that return Result (HTTP response which we send to web client).
I'm getting back to Play Framework again and I'm going to build simple start project.
Make sure you have java installed.
java -version
If java is installed you will see message like that:
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
brew install typesafe-activator
activator new hello-world
Activator will ask you what template you want to use for new project? (I used play-java).
1) minimal-akka-java-seed
2) minimal-akka-scala-seed
3) minimal-java
4) minimal-scala
5) play-java
6) play-scala
That will create a java project for us
Now let's run it. Go into newly create project and run activator
activator run
That will run our project and up server as well. You can access project by localhost:9000
//1. go to opt folder
cd /opt
//2. download java
wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u60-b27/jdk-8u60-linux-x64.tar.gz"
//3. extract java archive
tar xzf jdk-8u60-linux-x64.tar.gz
//4. installing java
cd /opt/jdk1.8.0_60/
alternatives --install /usr/bin/java java /opt/jdk1.8.0_60/bin/java 2
alternatives --config java
//5. recommended options: setup javac and jar
alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_60/bin/jar 2
alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_60/bin/javac 2
alternatives --set jar /opt/jdk1.8.0_60/bin/jar
alternatives --set javac /opt/jdk1.8.0_60/bin/javac
//6. setup variables so we can access java from everywhere
export JAVA_HOME=/opt/jdk1.8.0_60
export JRE_HOME=/opt/jdk1.8.0_60/jre
export PATH=$PATH:/opt/jdk1.8.0_60/bin:/opt/jdk1.8.0_60/jre/bin
//7. checking java version
java -version
//8. delete java archive
rm jdk-8u60-linux-x64.tar.gz
//1. go to tmp folder and download typesafe activator
cd /tmp
wget https://downloads.typesafe.com/typesafe-activator/1.3.6/typesafe-activator-1.3.6.zip
//2. unzip and move to opt folder
unzip typesafe-activator-1.3.6.zip
mv activator-dist-1.3.6 /opt
//3. delete zip file, we do not need it anymore
rm typesafe-activator-1.3.6.zip
//4. create soft symbolic link from /opt/activator-dist-1.3.6/activator to /usr/local/sbin/activator
ln -s /opt/activator-dist-1.3.6/activator /usr/local/sbin/activator
//5. set variables so we can use activator from everywhere
export PATH=/usr/local/sbin/activator:$PATH
//1. create folder www in /var (we are going to keep projects there).
cd /var
mkdir www
cd www
//2. have a look on current templates
activator list-templates
//3. create a new project based on play-java template
activator new helloworld play-java
//4. go into newly created project and run it
cd helloworld
activator run