Play framework - Compilation error[object inject is not a member of package javax]

4,413 views
Skip to first unread message

MJ

unread,
Apr 14, 2015, 5:39:09 PM4/14/15
to play-fr...@googlegroups.com

I would like to add to the table "Person" when you press the button "Add a Person" but I get an error:


play.PlayExceptions$CompilationException: Compilation error[object inject is not a member of package javax]

at play.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27) ~[na:na]

at play.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27) ~[na:na]

at scala.Option.map(Option.scala:145) ~[scala-library-2.11.1.jar:na]

...



controller is in the class Application:


package controllers

import play.api._
import play.api.mvc._
import play.api.data.Form
import play.api.data.Forms._
import play.api.libs.json.Json
import models._
import javax.inject._

class Application @Inject() (db: DB) extends Controller {

def index = Action {
Ok(views.html.index())
}

val personForm: Form[Person] = Form {
mapping(
"name" -> text
)(Person.apply)(Person.unapply)
}

def addPerson = Action { implicit request =>
val person = personForm.bindFromRequest.get
db.save(person)
Redirect(routes.Application.index)
}

}

models is in the class DB :

package models
import sorm._

class DB extends Instance(entities = Set(Entity[Person]()), url = "jdbc:h2:mem:test")


models is the class Person :

package models
import play.api.libs.json._

case class Person(name: String)

object Person {
implicit val personFormat = Json.format[Person]
}

views is the index.scala.html:
@()

@main("Welcome to Play") {
<script type='text/javascript' src='@routes.Assets.at("javascripts/index.js")'></script>

<ul id="persons"></ul>

<form method="POST" action="@routes.Application.addPerson()">
<input type="text" name="name"/>
<button>Add Person</button>
</form>
}

views is the index.scala.html:
@(title: String)(content: Html)

<!DOCTYPE html>

<html>
<head>
<title>@title</title>
<link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")">
<script src="@routes.Assets.at("javascripts/jquery-1.11.1.min.js")" type="text/javascript"></script
</head>
<body>
@content
</body>
</html>

conf is the routes:
GET     /                           controllers.Application.index
POST /person controllers.Application.addPerson
GET /assets/*file controllers.Assets.at(path="/public", file)

I do not know how to fix the problem. 
Please help. Thank you

James Roper

unread,
Apr 15, 2015, 12:39:42 AM4/15/15
to play-framework
Do you have jsr305 on your classpath?  Or more to the point, you're trying to use dependency injection, have you added a dependency injection provider?  See here for instructions:


--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
James Roper
Software Engineer

Typesafe – Build reactive apps!
Twitter: @jroper

MJ

unread,
Apr 15, 2015, 1:40:47 PM4/15/15
to play-fr...@googlegroups.com
Thank very you for your help in this matter.
I have version in java :

$> java -version
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)

my environment variables:

PATH
C:\Python34\;C:\Python34\Scripts;C:\ProgramData\Oracle\Java\javapath;D:\app\username\product\12.1.0\dbhome_1\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\maven\apache-maven-3.2.3\bin;C:\Program Files\Java\jre7\bin;C:\Program Files\Java\jre1.8.0_25\bin;C:\Program Files\Java\jdk1.8.0_25\bin;C:\Program Files\maven\apache-maven-3.2.3\bin;C:\Program Files (x86)\scala\bin;C:\Program Files (x86)\sbt\bin

SBT_HOME
C:\Program Files (x86)\sbt\


I used the help :

I added in the file conf/routes:
GET     /                           @controllers.Application.index
POST /person @controllers.Application.addPerson

GET /assets/*file controllers.Assets.at(path="/public", file)

and build.sbt:

name := """play-scala-intro"""
version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayScala)

scalaVersion := "2.11.1"

libraryDependencies ++= Seq(
jdbc,
anorm,
cache,
ws
)
routesGenerator := InjectedRoutesGenerator

but I still gets an error:

2015-04-15 19:27:13,140 - [ERROR] - from application in New I/O worker #8 


! @6lo66o22n - Internal server error, for (GET) [/] ->


play.PlayExceptions$CompilationException: Compilation error[object inject is not a member of package javax]
at play.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27) ~[na:na]
at play.PlayExceptions$CompilationException$.apply(PlayExceptions.scala:27) ~[na:na]
at scala.Option.map(Option.scala:145) ~[scala-library-2.11.1.jar:na]
   at play.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:49) ~[na:na]
at play.PlayReload$$anonfun$taskFailureHandler$1.apply(PlayReload.scala:44) ~[na:na]

at scala.Option.map(Option.scala:145) ~[scala-library-2.11.1.jar:na]
   at play.PlayReload$.taskFailureHandler(PlayReload.scala:44) ~[na:na]
at play.PlayReload$.compileFailure(PlayReload.scala:40) ~[na:na]
at play.PlayReload$$anonfun$compile$1.apply(PlayReload.scala:17) ~[na:na]
at play.PlayReload$$anonfun$compile$1.apply(PlayReload.scala:17) ~[na:na]
at scala.util.Either$LeftProjection.map(Either.scala:377) ~[scala-library-2.11.1.jar:na]
at play.PlayReload$.compile(PlayReload.scala:17) ~[na:na]
at play.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$2$$anonfun$apply$3$$anonfun$2.apply(PlayRun.scala:61) ~[na:na]
at play.PlayRun$$anonfun$playRunTask$1$$anonfun$apply$2$$anonfun$apply$3$$anonfun$2.apply(PlayRun.scala:61) ~[na:na]
at play.runsupport.Reloader.reload(Reloader.scala:295) ~[na:na]
at play.core.ReloadableApplication$$anonfun$get$1.apply(ApplicationProvider.scala:122) ~[play_2.11-2.3.8.jar:2.3.8]
at play.core.ReloadableApplication$$anonfun$get$1.apply(ApplicationProvider.scala:120) ~[play_2.11-2.3.8.jar:2.3.8]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) ~[scala-library-2.11.1.jar:na]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) ~[scala-library-2.11.1.jar:na]
at scala.concurrent.forkjoin.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1361) ~[scala-library-2.11.1.jar:na]
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) ~[scala-library-2.11.1.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) ~[scala-library-2.11.1.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) ~[scala-library-2.11.1.jar:na]
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) ~[scala-library-2.11.1.jar:na]

Please help. Thank you
 

James Roper

unread,
Apr 15, 2015, 11:56:56 PM4/15/15
to play-framework
So you're using Play 2.4?  You are aware that 2.4 has not been released yet, and so is not stable?  Only milestones have been released, and these are intended for experimentation only.  What is in your project/plugins.sbt?

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

MJ

unread,
Apr 16, 2015, 6:57:08 AM4/16/15
to play-fr...@googlegroups.com
plugins.sbt:

resolvers += "Typesafe repository" at "https://repo.typesafe.com/typesafe/releases/"

// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.8")
// web plugins

addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.0.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.1")

addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.1")

addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.0.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.0.0")


You do not know which version is correct and stable?
Thank you for your help.




W dniu wtorek, 14 kwietnia 2015 23:39:09 UTC+2 użytkownik MJ napisał:

MJ

unread,
Apr 20, 2015, 10:34:02 AM4/20/15
to play-fr...@googlegroups.com
works. Thank you.

Otherwise, the project ran
1. I downloaded
2. clicked
activator.bat
3. Deployed to me in your browser
4. I added the project;
5. I ran it in IntelliJ IDEA Community Edition 14.1.1
6. prepared to run

W dniu wtorek, 14 kwietnia 2015 23:39:09 UTC+2 użytkownik MJ napisał:
Reply all
Reply to author
Forward
0 new messages