运行使用 SBT 和 ProGuard 构建的独立 jar 时出现 AbstractMethodError

发布于 2024-10-08 05:46:43 字数 1939 浏览 0 评论 0原文

我编写了一个简单的 Scala 应用程序,希望以独立的可执行 jar 的形式分发到没有 Scala 运行时的服务器。通过 SBT run 调用时一切正常,但通过 java -jar 调用则不然。

当我通过 java 运行 jar 时,出现以下未处理的异常:

Exception in thread "main" java.lang.AbstractMethodError: java.util.logging.Handler.publish(Ljava/util/logging/LogRecord;)V
    at java.util.logging.Logger.log(Logger.java:458)
    at net.lag.logging.Logger.log(Logger.scala:108)
    at net.lag.logging.Logger.log(Logger.scala:91)
    at net.lag.logging.Logger.info(Logger.scala:121)
    at com.rentawebgeek.sitewiki.SiteWiki$.main(SiteWiki.scala:29)
    at com.rentawebgeek.sitewiki.SiteWiki.main(SiteWiki.scala)
Exception in thread "Thread-0" java.lang.AbstractMethodError: java.util.logging.Handler.close()V
    at java.util.logging.LogManager.resetLogger(LogManager.java:682)
    at java.util.logging.LogManager.reset(LogManager.java:665)
    at java.util.logging.LogManager$Cleaner.run(LogManager.java:223)

我正在使用 Configgy,它是 Logger,并且,根据 AbstractMethodError,认为这可能与使用与我从 shell 调用的 Java 版本不同的 Java 版本的 Scala/SBT 有关。但是,java -version$JAVA_HOME/bin/java -version/usr/local/bin/scala 使用的内容)都匹配如 1.6.0_22。

我的 ProGuard 选项是:

//program entry point
override def mainClass: Option[String] = Some("com.rentawebgeek.sitewiki.SiteWiki")

//proguard
override def proguardOptions = List(
    "-keepclasseswithmembers public class * { public static void main(java.lang.String[]); }",
    "-dontoptimize",
    "-dontobfuscate",
    "-keep class *",
    proguardKeepLimitedSerializability,
    proguardKeepAllScala,
    "-keep interface scala.ScalaObject"
)

override def proguardInJars = Path.fromFile(scalaLibraryJar) +++ super.proguardInJars

如何解决此错误?或者找到另一种方法从 SBT 项目构建可执行 jar 以进行无 Scala 部署?

I've written a simple Scala application that I'd like to distribute in the form of a standalone, executable jar to servers without the Scala runtime. Everything works fine when invoked through SBT run, but not java -jar.

When I run the jar through java, I get the following unhandled exception:

Exception in thread "main" java.lang.AbstractMethodError: java.util.logging.Handler.publish(Ljava/util/logging/LogRecord;)V
    at java.util.logging.Logger.log(Logger.java:458)
    at net.lag.logging.Logger.log(Logger.scala:108)
    at net.lag.logging.Logger.log(Logger.scala:91)
    at net.lag.logging.Logger.info(Logger.scala:121)
    at com.rentawebgeek.sitewiki.SiteWiki$.main(SiteWiki.scala:29)
    at com.rentawebgeek.sitewiki.SiteWiki.main(SiteWiki.scala)
Exception in thread "Thread-0" java.lang.AbstractMethodError: java.util.logging.Handler.close()V
    at java.util.logging.LogManager.resetLogger(LogManager.java:682)
    at java.util.logging.LogManager.reset(LogManager.java:665)
    at java.util.logging.LogManager$Cleaner.run(LogManager.java:223)

I'm using Configgy and it's Logger, and, per the javadocs for AbstractMethodError, thought it might be related to Scala/SBT using a different Java version than what I'm invoking from my shell. However, java -version and $JAVA_HOME/bin/java -version (what /usr/local/bin/scala uses) both match up as 1.6.0_22.

My ProGuard options are:

//program entry point
override def mainClass: Option[String] = Some("com.rentawebgeek.sitewiki.SiteWiki")

//proguard
override def proguardOptions = List(
    "-keepclasseswithmembers public class * { public static void main(java.lang.String[]); }",
    "-dontoptimize",
    "-dontobfuscate",
    "-keep class *",
    proguardKeepLimitedSerializability,
    proguardKeepAllScala,
    "-keep interface scala.ScalaObject"
)

override def proguardInJars = Path.fromFile(scalaLibraryJar) +++ super.proguardInJars

How can I resolve this error? Or find another way to build an executable jar from an SBT project for a Scala-less deployment?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清旖 2024-10-15 05:46:44

查看您在 SiteWiki.scala 的第 29 行进行的调用;这就是违规电话。您可能正在使用抽象方法调用特征/类。最有可能的是,应该实现抽象方法的方法被 proguard 剥夺了(或者 Scala 重写不匹配(我见过这种情况发生))。

如果队伍很长才能找到有问题的电话;尝试分解为多行。

Check out what call you are making at line 29 in SiteWiki.scala; that is the offending call. You're probably calling a trait/class there with an abstract method. Most probably the method that should implement the abstract method is ripped away by proguard (or there the Scala override doesn't match up (I've seen that happen)).

If the line is long to find the offending call; try to decompose over multiple lines.

缱绻入梦 2024-10-15 05:46:44

最新的 ProGuard 版本包含用于处理 Scala 应用程序和 Scala 运行时的示例配置:

http://proguard.sourceforge.net/manual/examples.html#scala" rel="nofollow">http:// /proguard.sourceforge.net/manual/examples.html#scala

如果这不起作用,-printconfiguration 的输出和控制台输出可能有助于查找根本原因。

The latest ProGuard releases contain a sample configuration for processing a Scala application plus the Scala runtime:

http://proguard.sourceforge.net/manual/examples.html#scala

If that doesn't work, the output of -printconfiguration and the console output might help finding the root cause.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文