【问题标题】:sbt unmanagedClasspath entry for lift compiles but not found at runtime用于提升编译但在运行时未找到的 sbt unmanagedClasspath 条目
【发布时间】:2013-06-01 08:27:59
【问题描述】:

我的 lift sbt 文件中有一个 unmanagedClasspath 条目,它指向外部 java 项目的类。它编译得很好,但是当它运行时我得到一个 NoClassDefError 。下面是 sbt 条目,后面是 NoClassDefError 的一些痕迹。

非常感谢任何帮助

unmanagedClasspath in Compile += file("[Path to my project]/classes")

 ERROR n.liftweb.http.provider.HTTPProvider - Failed to Boot! Your application may not run properly
java.lang.NoClassDefFoundError: com/myproject/MyClass
    at bootstrap.liftweb.Boot.boot(Boot.scala:70) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_21]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_21]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_21]
    at java.lang.reflect.Method.invoke(Method.java:601) ~[na:1.7.0_21]
    at net.liftweb.util.ClassHelpers$$anonfun$createInvoker$1.apply(ClassHelpers.scala:364) ~[lift-util_2.9.1-2.5-RC2.jar:2.5-RC2]
    at net.liftweb.util.ClassHelpers$$anonfun$createInvoker$1.apply(ClassHelpers.scala:362) ~[lift-util_2.9.1-2.5-RC2.jar:2.5-RC2]
    at net.liftweb.http.DefaultBootstrap$$anonfun$boot$1.apply(LiftRules.scala:1999) ~[lift-webkit_2.9.1-2.5-RC2.jar:2.5-RC2]
    at net.liftweb.http.DefaultBootstrap$$anonfun$boot$1.apply(LiftRules.scala:1999) ~[lift-webkit_2.9.1-2.5-RC2.jar:2.5-RC2]
    at net.liftweb.common.Full.map(Box.scala:553) ~[lift-common_2.9.1-2.5-RC2.jar:2.5-RC2]

【问题讨论】:

    标签: scala sbt lift


    【解决方案1】:

    unmanagedJars in CompileRuntimeTest中作为同一个key的base,所以它的内容被Runtime继承,但是unmanagedClasspath不是这样。这就是为什么你应该尽可能选择unmanagedJars

    您可以将文件夹显式添加到两种配置中:

    val additionalClasses = file("[Path to my project]/classes")
    
    unmanagedClasspath in Compile += additionalClasses
    
    unmanagedClasspath in Runtime += additionalClasses
    

    注意:sbt build.sbt 中的 val,因此您必须在两种设置中复制其内容,或者切换到完整的 Build.scala

    请参阅Classpaths docsthis anwser,了解有关类路径设置的作用以及它们如何在配置之间继承的更多详细信息。

    我想不出同时将它添加到两者的方法......

    【讨论】:

    • 谢谢你的工作。唯一的问题是 sbt 不喜欢第一行的语法,所以我不能使用 AdditionalClasses 定义,但必须为 Compile 和 Runtime 显式添加类路径
    • 哦,你是说val?对,你不能在 sbt build.sbt 中添加 val。您必须复制file(...) 或使用Build.scala 文件。我会编辑答案。
    猜你喜欢
    • 2013-03-04
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    • 1970-01-01
    • 2018-01-07
    • 2014-02-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多