Skip to content

Installing MEF

ianrae edited this page Jan 25, 2014 · 10 revisions

MEF is available as a github repository. Include it in your project by following these instructions.

build.sbt

New in Play 2.2 is build.sbt which replaces Build.scala.

In build.sbt add mettle to dependencies:

libraryDependencies ++= Seq(
  javaJdbc,
  javaEbean,
  cache,
  "mettle" % "mettle_2.10" % "0.2-SNAPSHOT"  //** add this line**
)     

And add a resolver to get mettle from github:

resolvers ++= Seq(
Resolver.url("Mettle Repository", new URL("http://ianrae.github.io/snapshot/"))(Resolver.ivyStylePatterns)
//)

`

Build.scala (for older projects ported from Play 2.1)

Add this to your appDependencies:

 "mettle" % "mettle_2.10" % "0.2-SNAPSHOT"

Then set your project to include a resolver:

val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
  resolvers += Resolver.url("Mettle Repository", url("http://ianrae.github.io/snapshot/"))(Resolver.ivyStylePatterns),
  checksums := Nil
)

Add the lib directory

Copy the lib directory from the AppTwo sample (code/internal-samples/AppTwo). This contains the StringTemplate ST-4.0.7.jar which is needed for code generation. StringTemplate is not used by MEF at runtime.

Run app and create Eclipse or IDEA project

play eclipse
play run

Open your browser to localhost:9000 and you should see the Play start page for a new project.

Create your code generation

Eventually MEF will add commands in SBT. Until then, use JUnit tests to do code generation

Create an mgen source folder

In the root of your project create mgen folder and add as source folder (in Java Build Path in Eclipse). You should now how three source folders

app
mgen
test

Create a new JUnit class MGen.java

Create MGen.java in the mgen directory. Paste in the following code:

	public class MGen extends MGenBase
	{
		@Test
		public void test() throws Exception 
		{
			this.runCodeGeneration();
		}
	}

And run it. This will create the mef directory structure and some initial files.

app
boundaries     layer that sits between Play and MEF

mef
    core        initialization code
    dals        (daos) database persistence
    entities    the 'model object in MEF (POJOs)
    gen         codegen puts stuff here
    presenters  holds business logic. equivalent to a controller

conf
  mef/seed       JSON database initialization files

test
  mef            unit tests (no FakeApplication needed)

Final steps

Add the following to routes

# Error
GET 	/logout                 controllers.ErrorController.logout()
GET 	/showError                 controllers.ErrorController.showError(msg:String)

You're Ready to begin building your Entities and Presenters


Clone this wiki locally