I cannot use ebean in play framework - playframework-2.4

I'm using play 2.4. I got compilation error: package "com.avaje.ebean" does not exist. Need help, appreciate!

Play's Ebean is now an external project. You need to add a dependency in your project/plugins.sbt file:
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "1.0.0")
In your build.sbt file, enable the plugin:
lazy val myProject = (project in file(".")).enablePlugins(PlayJava, PlayEbean)
All this information and more is available in the 2.4 migration guide.

Related

How to install library with SBT libraryDependencies in an Intellij project

I am very new to SBT, Breeze and IntelliJ, though I have a decent grasp of Scala and I am trying to install the Breeze library, which I think is managed.
What I've done:
I followed the instructions on this page and added this script to the build.sbt file in my project:
libraryDependencies ++= Seq(
// other dependencies here
"org.scalanlp" %% "breeze" % "0.10",
// native libraries are not included by default. add this if you want them (as of 0.7)
// native libraries greatly improve performance, but increase jar sizes.
"org.scalanlp" %% "breeze-natives" % "0.10"
)
resolvers ++= Seq(
// other resolvers here
"Sonatype Releases" at "https://oss.sonatype.org/content/repositories/releases/"
)
// Scala 2.9.2 is still supported for 0.2.1, but is dropped afterwards.
scalaVersion := "2.11.1" // or 2.10.3 or later
I then ran sbt update in the project directory (via the terminal), and saw that all the pieces of Breeze downloaded.
I then tried re-running sbt update, but this did not trigger another download.
Issue:
The problem is that I cannot access the library via IntelliJ. import breeze._ gives the standard Cannot resolve symbol breeze and I couldn't find any mention of Breeze in "Project Structure." It isn't in the lib directory of the project either.
Am I missing a step?
Sounds like a bug in the IntelliJ project, try removing the .idea directory from the project directory and then re-import the project into IntelliJ using the wizard.

How to use play-plugins-mailer with Play 2.3 and Scala 2.11?

I am trying to use the play plugin for sending emails:
https://github.com/playframework/play-mailer
I have followed the instructions as found on github: added the dependency to build.sbt, created play.plugins with the specified content (do I need to register the file somehow)?
but I get a compilation error:
object mailer is not a member of package play.api.libs
when trying to import
import play.api.libs.mailer._
I get another compilation error on
val mail = use[MailerPlugin].email
MailerPlugin and use are not found.
How to get this working?
Note: the plugin is correctly downloaded (I can find it in my .ivy2 directory), but it is not listed as a dependency in my application.
My build.sbt file:
name := ...
version := "1.0-SNAPSHOT"
scalaVersion := "2.11.2"
resolvers += Resolver.typesafeRepo("releases")
//"mysql" % "mysql-connector-java" % "5.1.31"
libraryDependencies ++= Seq(
"mysql" % "mysql-connector-java" % "5.1.24",
"org.webjars" %% "webjars-play" % "2.3.0-2",
"com.typesafe.play" %% "play-slick" % "0.8.0",
"com.typesafe.play.plugins" %% "play-plugins-mailer" % "2.3.1",
"org.mindrot" % "jbcrypt" % "0.3m"
)
fork in Test := false
lazy val root = (project in file(".")).enablePlugins(PlayScala)
And my play.plugins contains only:
1500:com.typesafe.plugin.CommonsMailerPlugin
UPDATE:
I've downloaded the sample project from https://github.com/playframework/play-mailer
and tried to compile using sbt. It failed with exactly the same problem.
It looks like the problem is somehow with the version of plugin that is available in the typesafe repo:
I've built the plugin from sources, published it to my local repository and then everything compiled fine.
In the build.sbt of the sample app there is:
resolvers += Resolver.file("LocalIvy", file(Path.userHome + File.separator + ".ivy2" + File.separator + "local"))(Resolver.ivyStylePatterns)
So it looks like the authors also had problems in compiling the app using the plugin deployed to the official repository.
UPDATE:
Well, it compiled fine, but then failed at runtime with java.lang.ClassNotFoundException: com.typesafe.plugin.CommonsMailerPlugin
UPDATE 2:
The sample play.plugins is also wrong, the correct one should be:
1500:play.api.libs.mailer.CommonsMailerPlugin
and then eveyrthing finally works
The README is up to date with the latest development (upcoming version).
As of 19/12/2014, the latest version released and available in the Typesafe repository is 2.3.1. If you want to use this version you need to refer to the README in the v2.3.1 tag: https://github.com/playframework/play-mailer/tree/v2.3.1
For the upcoming version we have decided to break compatibility to move the Play mailer into its own package and provide a better implementation. That's the reason why the documentation in the master branch is not working with version 2.3.1.

Typesafe Play WS as dependency in SBT project

Since Play Framework 2.3.x, Play WS is a dependent library. Reference:
http://playframework.com/documentation/2.3.x/Migration23
How do I include it in a SBT project?
Answer:
"com.typesafe.play" %% "play-ws" % "2.3.1"
Guys for anyone who stumbled it's better to add the following line:
libraryDependencies += javaWs
For Build.scala you should import play.Play.autoImport._ in order to use the ws pattern.
In build.sbt you can use it off the bat.

Scala Playframework 2.2 - HtmlUnit missing

I have a project using Playframework 2.2
I eclipsified it and in my code I write something like this:
import com.gargoylesoftware.htmlunit.WebClient
val client = new WebClient
Eclipse says everything's fine, but when I play run my application I get a following message:
[error] C:\workspace\kwiket\kwiketscala\app\service\parsers\HTMLParser.scala:11: object gargoylesoftware is not a member of package com
[error] import com.gargoylesoftware.htmlunit.WebClient
How could I fix this? What dependencies should I add to my project? Thanks
In the test configuration is HTMLUnit available, but you need it in the compile configuration.
Just update your libraryDependencies in build.sbt:
libraryDependencies ++= Seq(
jdbc,
anorm,
cache,
"net.sourceforge.htmlunit" % "htmlunit" % "2.13" //found on http://search.maven.org/#artifactdetails%7Cnet.sourceforge.htmlunit%7Chtmlunit%7C2.13%7Cjar section SBT
)
Restart SBT or execute reload.

Scalate sbt 0.11.0 plugin help

I'm developing a Scalatra web app with Scalate Jade and using sbt 0.11.0
I've been packaging the web app with "com.github.siasia" %% "xsbt-web-plugin" % "0.1.2".
I've also been experimenting with "com.zentrope" %% "xsbt-scalate-precompile-plugin" % "1.6" to compile the Jade files.
Unfortunately if I use the xsbt-web-plugin to package my war it clears the target directory from any precompiled Scalate files.
What is the best way to package a war with precompiled Scalate files?
Thanks to Keith Irwin, the author of xsbt-scalate-precompile-plugin, I now have a solution to my problem.
My Jade/Scalate files are in webapp/WEB-INF/template and webapp/WEB-INF/scalate/layouts directories.
I'm using the xsbt-web-plugin and xsbt-scalate-precompile-plugin sbt plugins.
xsbt-web-plugin provides me with the package-war command.
xsbt-scalate-precompile-plugin pre-compiles my Jade files.
In my plugins.sbt file.
resolvers += "Web plugin repo" at "http://siasia.github.com/maven2"
addSbtPlugin("com.github.siasia" %% "xsbt-web-plugin" % "0.1.2")
resolvers += "zentrope" at "http://zentrope.com/maven"
addSbtPlugin("com.zentrope" %% "xsbt-scalate-precompile-plugin" % "1.7")
In my build.scala file.
import WebPlugin._
import Keys._
import com.zentrope.ScalatePlugin._
...
// WebApp Settings
val webAppSettings = Seq(
jettyPort := 8083,
jettyContext := "/MyWebApp"
)
// Scalate Compile Settings
val scalateCompileSettings = scalateTemplateSettings ++ Seq(
scalateTemplateDirectories in Compile <<= (scalateTemplateDirectories in Compile, baseDirectory) {
(dirs, basedir) => dirs ++ Seq(new File(basedir, "/src/main/webapp/WEB-INF/template"),
new File(basedir, "/src/main/webapp/WEB-INF/scalate/layouts"))
}
)
...
lazy val MyWebApp =
Project("MyWebApp", file("MyWebApp"), settings = shared ++ webAppSettings ++ scalateCompileSettings ++ Seq(
resolvers ++= Seq(sonatypeNexusReleases, scalaToolsNexus, novusRels, scalaToolsSnapshots),
libraryDependencies ++= Seq(
scalatra,
scalate,
...
)
))
The 1.7 version of Keiths' plugin allows for the setting of specific template directories which is what I really needed. The only caveat is that I must do a clean right before I call package-war or my compiled Jade files get removed.
I'm not sure I understand you here. Anything that's source should be in src. One should never put anything in target. Resources would naturally go into src/main/resources. So, are these "precompiled" files something that is being automatically generated, or should they have been in the resources directory?