swaheed swaheed - 1 year ago 42
Java Question

play compile error Cannot access term libs in value <root>.api. The current classpath may be missing a definition for <root>.api.libs,

I have a play application named

myApp
and in which I have a sub-project named
searching
. I want to access the model class that is present in myApp(root project) in my sub-project
searching
. Then I decided to create another sbt independent project named
common
and in that project I put the model classes and run the package on it. It created a jar for me then i dropped this jar in my play's sub-project
searching
lib directory.
Now the problem is when I am trying to compile my play project along with sub-project play is giving me that error:

myApp>activator
[info] Compiling 45 Scala sources to /media/sara/682AA7A32AA76D2E/study/project/Searching/target/scala-2.11/classes...
[error] bad symbolic reference to <root>.play encountered in class file 'Delete.class'.
[error] Cannot access term play in package <root>. The current classpath may be
[error] missing a definition for <root>.play, or Delete.class may have been compiled against a version that's
[error] incompatible with the one found on the current classpath.
[error] bad symbolic reference to play.api encountered in class file 'Delete.class'.
[error] Cannot access term api in value play. The current classpath may be
[error] missing a definition for play.api, or Delete.class may have been compiled against a version that's
[error] incompatible with the one found on the current classpath.
[error] bad symbolic reference to <root>.api.libs encountered in class file 'Delete.class'.
[error] Cannot access term libs in value <root>.api. The current classpath may be
[error] missing a definition for <root>.api.libs, or Delete.class may have been compiled against a version that's
[error] incompatible with the one found on the current classpath.
[trace] Stack trace suppressed: run last testSearching/compile:compile for the full output.
[error] (testSearching/compile:compile) scala.reflect.internal.Types$TypeError: bad symbolic reference to <root>.libs.json encountered in class file 'Delete.class'.
[error] Cannot access term json in value <root>.libs. The current classpath may be
[error] missing a definition for <root>.libs.json, or Delete.class may have been compiled against a version that's
[error] incompatible with the one found on the current classpath.
[error] Total time: 14 s, completed Oct 20, 2015 1:29:37 PM


I am using play 2.3.8; my play project
myApp
has following directory structure

-app
--models
---Delete.scala
-Searcing
-src/main/scala
-------Demo.scala
-lib
--common.jar


here is the code of Delete.scala

package models

//import play.api.libs.json.Json
import play.api.libs.json._

@SerialVersionUID(1)
case class Delete( var deleteStatusInt : Int = 0 , var deleteReasonInt : Int = 0) extends Serializable {

def getDeleteStatusInt =DeleteStatus(deleteStatusInt)
def getDeleteReasonInt =DeleteReason(deleteReasonInt)

}

object Delete {
implicit val deleteFormat = Json.format[Delete]
}


and Demo.scala is not using Delete.Scala code

here is the build file of myApp project

name := """myApp"""

version := "1.0-SNAPSHOT"

lazy val project = (project in file(".")).enablePlugins(PlayScala)
.aggregate(searching)
.dependsOn(searching)

scalaVersion := "2.11.1"

fork in run := true

javaOptions in run ++= Seq("-J-Xms1G", "-J-Xmx2G")

val appDependencies = Seq(
// Add your project dependencies here,
"org.scalatestplus" %% "play" % "1.2.0" % "test"
)

lazy val searching = project


libraryDependencies ++= Seq(""org.apache.lucene" % "lucene-expressions" % "4.10.4",
"com.typesafe.akka" %% "akka-actor" % "2.3.6",
)


here is the build file of searching sub-project

name := """searching"""

version := "1.0-SNAPSHOT"

scalaVersion := "2.11.1"

libraryDependencies ++= Seq("org.apache.lucene" % "lucene-expressions" % "4.10.4",
"com.typesafe.akka" %% "akka-actor" % "2.3.6")


and the independent sbt project I created, Has the following structure

common
-src/main/scala
--models
---Delete.scala


and here is the code of Delete.scala

package models

//import play.api.libs.json.Json
import play.api.libs.json._

@SerialVersionUID(1)
case class Delete( var deleteStatusInt : Int = 0 , var deleteReasonInt : Int = 0) extends Serializable {

def getDeleteStatusInt =DeleteStatus(deleteStatusInt)
def getDeleteReasonInt =DeleteReason(deleteReasonInt)

}

object Delete {
implicit val deleteFormat = Json.format[Delete]
}


here is the build.sbt for the common project

name := "common"

version := "1.0-SNAPSHOT"

organization := "models"

scalaVersion := "2.11.1"

publishMavenStyle := true

libraryDependencies ++= Seq("org.apache.lucene" % "lucene-expressions" % "4.10.4",
//"com.typesafe.play" % "play-json_2.11" % "2.3.8",
"com.typesafe.play" % "play_2.11" % "2.3.8",
"com.typesafe.akka" %% "akka-actor" % "2.3.6"
)


Please help me

Answer Source

i solved this issue by adding play library dependency in searching build.sbt file

name := """searching"""

version := "1.0-SNAPSHOT"

scalaVersion := "2.11.1"

libraryDependencies ++= Seq("org.apache.lucene" % "lucene-expressions" % "4.10.4",
"com.typesafe.play" % "play_2.11" % "2.3.8",
                "com.typesafe.akka" %% "akka-actor" % "2.3.6")

the problem was occurring because i did not add the same libraries as used in the project whose jar is been used so adding those libraries in seraching project build.sbt solves the issue

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download