Wednesday 10 July 2013

PlayFrameWork Tutorail on installation on Ubuntu and Configure Mysql.

Hello every today i will show how you install and create your 1st application on playfarmework

Step 1)
             Download PlayframeWork :

               http://downloads.typesafe.com/play/2.1.2/play-2.1.2.zip

Step 2)
             Download and Extract and Install play on ubuntu. Foe installation you have to give the path in the .bashrc this file is hidden in the your user home folder for find it press Ctrl+h and you able to see the hidden file of your system then open .bashrc in the any text editor you like and give the following path on in that file

             export PATH=$PATH:/home/trainee02/play
 /*Note you can replace  trainee02 with your username*/

Step 3)
             Once you had done above steps then open your terminal and type play
you will get play shell. Now we have to create application in the play for that you have to give the following command :

                   $play new demoapp

Then it will create your application next thing we have to do is we have to chose the platform on which we have to create our application like on java or scala in my case i am using java :) .

Step 4)

            Then type command :
                      $cd demoapp/
and you are in your application. Then give command play and you get play shell. Before run your application give the following command to convert your application in the eclipse project for that you have to give the following command :

                     $play eclipse  
This command will convert you application and you can open it into the you
eclipse editor 
 
Step 5)
             After converted it into the eclipse again give command play you get play shell and now you can run your application. then give command run and your application now running successfully . you can see it is running on following port :
/0.0.0.0:9000

past this into your browser and you get your first application running.

Step  6)

             We have to create database application with Mysql for that we have to edit following in the project .
  
  1st file is : application.conf in conf folder 

# Database configuration
# ~~~~~
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:mem:play"
db.default.logStatements=true

# Ebean configuration
# ~~~~~
# You can declare as many Ebean servers as you want.
# By convention, the default server is named `default`
ebean.default="models.*"


 This is for connect database to our application .At regis you can put your database name. At the place of user root you can use your username of mysql and same with password. We have to enable ebean.deafult="models.*"

Step 7)

            Then we have to edit the Build.scala which is responsible for all the configure api .
 
        val appDependencies = Seq(
        // Add your project dependencies here,
      "mysql" % "mysql-connector-java" % "5.1.18"
        )

    
     This is for applying Driver in our application .        
 
Step 8)

            Then we have to create models folders in the app folder for our ebean on the name of ebean our table will be created the same name.

Step 9)
  
            Now we have to create our class form which we can able to create out table . I am putting up an sample code here .

package models;

import java.util.*;
import javax.persistence.*;

import play.db.ebean.*;
import play.data.format.*;
import play.data.validation.*;

import com.avaje.ebean.*;

/**
 * Project entity managed by Ebean
 */
@Entity
public class Project extends Model {

    @Id
    public Long id;
   
    public String name;
   
    public String folder;
   
   
   
    public Project(String name, String folder) {
        this.name = name;
        this.folder = folder;
    }


Step 10)

               Then we have to run application again and we get one exception on our web browser which is asking for apply our script . If we get that kind of exception the yes :) we did all thing fine and check your database you get new table with the name of our class.

Done .


 



No comments:

Post a Comment