gpt4 book ai didi

java - Play 编译错误无法访问值 .api 中的术语库。当前类路径可能缺少 .api.libs 的定义,

转载 作者:太空宇宙 更新时间:2023-11-04 13:19:29 24 4
gpt4 key购买 nike

我有一个名为 myApp 的 Play 应用程序,其中有一个名为 searching 的子项目。我想访问我的子项目 searching 中 myApp(根项目) 中存在的模型类。然后我决定创建另一个名为 common 的 sbt 独立项目,并在该项目中放置模型类并在其上运行包。它为我创建了一个 jar,然后我将这个 jar 放入我的 play 的子项目 searching lib 目录中。现在的问题是,当我尝试编译我的 play 项目以及子项目 play 时,出现了错误:

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

我使用的是play 2.3.8;我的游戏项目 myApp 具有以下目录结构

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

这是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]
}

并且 Demo.scala 未使用 Delete.Scala 代码

这是 myApp 项目的构建文件

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",
)

这里是搜索子项目的构建文件

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")

以及我创建的独立sbt项目,具有以下结构

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

这是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]
}

这是公共(public)项目的build.sbt

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"
)

请帮助我

最佳答案

我通过在搜索 build.sbt 文件中添加 Play 库依赖项解决了这个问题

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")

出现问题的原因是我没有添加与使用其 jar 的项目中使用的库相同的库,因此在 seraching 项目 build.sbt 中添加这些库可以解决问题

关于java - Play 编译错误无法访问值 <root>.api 中的术语库。当前类路径可能缺少 <root>.api.libs 的定义,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33232379/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com