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.
Related
Relatively new to sbt and Mockito.
I want to use Mockito in tests, but I'm getting errors related to the Mockito imports when I compile the tests
Imports in test file:
import org.scalatest._
import org.mockito.Mockito._
import org.scalatest.mockito.MockitoSugar
sbt file:
name := "blah"
version := "0.1"
scalaVersion := "2.13.0"
libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.8"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.8" % "test"
libraryDependencies += "org.mockito" % "mockito-core" % "1.8.5" % "test"
I get these error messages when the tests (fail to) compile:
object mockito is not a member of package org [error] import org.mockito.Mockito._
and also:
Symbol 'type org.mockito.MockSettings' is missing from the classpath.
[error] This symbol is required by 'value org.scalatest.mockito.MockitoSugar.mockSettings'.
I've had a play around with changing some of the versions of scalatest and mockito in the sbt file, but not really if that's getting at the root of the problem or not.
Thanks for any help!
You're using a very old version of Mockito, which is older than the one Scalates relies on, you probably need some 2.x.x version.
On the other hand, I'd recomend you to go fo mockito-scala rather than mockito-core and skip the Scalatest provided classes altogether as they are quite basic.
I suspect you have a caching problem. This happens especially with Intellij.
Here 2 ideas:
Reload the sbt project. See https://stackoverflow.com/a/20466144/2750966
Close the project / delete .idea an open the project newly with Intellij.
Let me know if it is not related with Intellij
I have the same issue raised here. I'm using Play 2.5.10, Scala 2.11.7 and sbt 0.13.11
I'd like to import common packages in every template.
I get a build error when I use the following in my build.sbt:
templatesImport ++= Seq(
"helper._",
"play.api._"
)
Build error:
build.sbt: error: not found: value templatesImport
Found the solution here:
Changed it to:
TwirlKeys.templateImports ++= Seq(
"helper._",
"play.api._"
)
I'm trying to make my first tests with Scala and with Play framework.
I have installed play 2.2.0, which seems to be the last version, with the standalone package. After that, I've been able to create a new application, compile and run it.
I've tried to start to use Anorm package to access to the database, but I've found a blocking error which I can't find on the docs. I don't know if that means that is so obvious, but after adding:
package controllers
import play.api._
import play.api.mvc._
import play.db.anorm._ //(this is the new line)
object Application extends Controller {
def index = Action {
Ok(views.html.index("Your new application is ready."))
}
}
It fails with:
object db is not a member of package play
I've seen this:
https://groups.google.com/forum/#!msg/play-framework/RUbmEVsw2rY/UOE5mNs1WjoJ
Where they talk about adding the dependency to jdbc, which seems to be already in my build.sbt.
libraryDependencies ++= Seq(
jdbc,
anorm,
cache
)
I've also found this thread here:
play.db package not found in play 2.1.3
But I can't find a build.scala file on my project. Not using any IDE by now, just play console (run & compile commands).
Thanks a lot!
In fact (as the error explains), there is no package play.db.anorm._ in version 2.2.0. Try use import anorm._ instead.
You need the following libraries
slick
play-jdbc
anorm
This is how my dependencies look like in build.sbt :
libraryDependencies ++= Seq(
"com.typesafe.slick" % "slick_2.10" % "2.1.0",
"org.postgresql" % "postgresql" % "9.4-1201-jdbc41",
"com.typesafe.play" % "play-jdbc_2.10" % "2.4.0-RC1",
cache,
anorm
)
Search for the latest version of library at Maven Central Repository
I have an application build on top of the Play framework 2.0.4. I would like to migrate it to the newest version (which is currently 2.2.0).
So I've updated my local Play framework installation, all build files accordingly:
build.properties:
sbt.version=0.13.0
Build.scala:
import sbt._
import Keys._
import play.Project._
object ApplicationBuild extends Build {
val appName = "demagog"
val appVersion = "1.0.0"
val appDependencies = Seq(
javaCore,
"com.google.code.morphia" % "morphia" % "0.99",
"com.google.code.morphia" % "morphia-logging-slf4j" % "0.99",
"net.tanesha.recaptcha4j" % "recaptcha4j" % "0.0.7"
)
val main = play.Project(appName, appVersion, appDependencies).settings(
// Add your own project settings here
resolvers += "Morphia repository" at "http://morphia.googlecode.com/svn/mavenrepo/"
)
}
plugins.sbt:
// Comment to get more information during initialization
logLevel := Level.Warn
// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
// Use the Play sbt plugin for Play projects
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.0")
Then I tried to "eclipsify" my project. So I run exactly these two commands:
play clean-all
play eclipse
and I get lots of errors like:
[error] ..\Api.java:11: error: package org.codehaus.jackson does not exist
import org.codehaus.jackson.JsonNode;
which is expected due to the fact I found in the Migration guide:
We have upgraded Jackson to version 2 which means that the package name is now com.fasterxml.jackson.core instead of org.codehaus.jackson.
But at the end of "play eclipse" command I get this error:
[error] (compile:compile) javac returned nonzero exit code
[error] Could not create Eclipse project files:
[error] Error evaluating task 'dependencyClasspath': error
So the project is not "eclipsified" and I can't use it nor edit in my Eclipse IDE. This compiling on backgroung outside of the Eclipse IDE is really painfull and prevents me from productive using Play framework :-/
You can delete all source code files, generate the IDE files and then restore the source code from version control.
Sadly that is how the eclipse (and idea) plugin work, you will have to have a working project before you can re-export the project from SBT to eclipse. So you will just have to work through the compilation errors without the usual support from eclipse.
So I've been trying to get IDEA 12.0 to work with Play 2.1.0 and Scala 2.10.0. I've just about given up because it's not working for me the way I want it to. Here is a copy of my build.properties, Build.scala, and plugins.sbt. I followed the approach on the playframework site to execute idea with-sources=yes in the play console. I've also tried adding sbt-idea plugin version 1.3.0-SNAPSHOT as seen in plugins.sbt, but nothing seems to work if I want to reference a new view template I just created or a new route. The only way I can work in IDEA is if I have a console open and run sbt compile, go back to IDEA, and it will refresh itself and recognize the new view templates or routes.
plugins.sbt
logLevel := Level.Warn
scalaVersion := "2.10.0"
// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
// Sonatype snapshots to get sbt-idea 1.3.0-SNAPSHOT
//resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
// Use the Play sbt plugin for Play projects
addSbtPlugin("play" % "sbt-plugin" % "2.1.0")
//addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.3.0-SNAPSHOT")
build.properties
sbt.version=0.12.2
Build.scala
import sbt._
import Keys._
import play.Project._
object ApplicationBuild extends Build {
val appName = "admin-application"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
// Add your project dependencies here,
jdbc,
anorm
)
val main = play.Project(appName, appVersion, appDependencies).settings(
// Add your own project settings here
)
}
If you use IDEA Community edition, there is a SBT Console plugin (see http://plugins.jetbrains.com/plugin?pluginId=5007) that allows you to compile / run your Play project directly in the editor. That's the way I work every day and it is fine (I use the ~run command and then don't care anymore).
You may also add a remote debugger in IDEA that listens to you local server (it it is run with debug mode on) and use it as usual.
If you use IDEA Ultimate edition, JetBrains released a Play Framework plugin that seems to work fine (but I haven't tested it yet). Have a look at these tutorials:
http://confluence.jetbrains.com/display/IntelliJIDEA/Play+Framework+2.0 or
http://www.jamesward.com/2013/01/23/video-create-and-run-play-framework-apps-in-intellij
Hope this helps.
I think this is how it work currently. As suggested by #pedrofurla, you can keep ~run running on sbt/play console. Sadly, IMO there is no other way IntelliJ can compile your scala views automatically.
Just add to project/plugins.sbt the following and re-run play idea
// FIX SBT IDEA PLAY 2.1
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
// Use the Play sbt plugin for Play projects
addSbtPlugin("play" % "sbt-plugin" % "2.1.0")