当依赖项位于buiild.sbt中时,获取java.lang.NoClassDefFoundError:javax / ws / rs / Path

时间:2019-05-02 12:31:14

标签: java scala sbt

我在 build.sbt 中进行了以下设置:

lazy val proj = (project in file("."))
  .settings(
    name := "Proj",
    resolvers += Resolver.mavenLocal,
    libraryDependencies += "javax.ws.rs" % "javax.ws.rs-api" % "2.1" artifacts( Artifact("javax.ws.rs-api", "", "jar")), // for rescu
    libraryDependencies += "com.github.mmazi" % "rescu" % "2.0.2",
  )

但是sbt run出现此错误:

[error] java.lang.NoClassDefFoundError: javax/ws/rs/Path
[error]     at si.mazi.rescu.RestInvocationHandler.<init>(RestInvocationHandler.java:61)

Path类存在于存档中

$ jar -tvf /home/user/.m2/repository/javax/ws/rs/javax.ws.rs-api/2.1/javax.ws.rs-api-2.1.jar | grep Path
   ...
   456 Fri Aug 04 15:17:40 MSK 2017 javax/ws/rs/Path.class

rs api以这种hacky方式添加,因为否则它拒绝插入,但是现在看来可以插入,但是我不知道有什么问题

1 个答案:

答案 0 :(得分:0)

通过反复试验,我最终得到了以下一组依赖关系,这些依赖关系解决了此问题:

libraryDependencies += "javax.ws.rs" % "javax.ws.rs-api" % "2.1" artifacts( Artifact("javax.ws.rs-api", "", "jar") ),
libraryDependencies += "javax.ws.rs" % "jsr311-api" % "1.1.1",
libraryDependencies += "org.apache.cxf" % "cxf-rt-frontend-jaxrs" % "3.3.1",
libraryDependencies += "com.github.mmazi" % "rescu" % "2.0.2",