1

我有一个 sbt 项目,应该创建一个可运行的 jar 文件。虽然正确创建了 jar,但启动它时会引发异常:

  Exception in thread "main" java.lang.reflect.InvocationTargetException
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at com.simontuffs.onejar.Boot.run(Boot.java:340)
            at com.simontuffs.onejar.Boot.main(Boot.java:166)
    Caused by: java.lang.RuntimeException: Exception in Application start method
            at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
            at com.sun.javafx.application.LauncherImpl.access$000(Unknown Source)
            at com.sun.javafx.application.LauncherImpl$1.run(Unknown Source)
            at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.NoClassDefFoundError: scala/util/parsing/combinator/RegexParsers
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClass(Unknown Source)
            at com.simontuffs.onejar.JarClassLoader.defineClass(JarClassLoader.java:803)
            at com.simontuffs.onejar.JarClassLoader.findClass(JarClassLoader.java:710)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at com.simontuffs.onejar.JarClassLoader.loadClass(JarClassLoader.java:630)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at org.streum.configrity.package$.<init>(package.scala:8)
            at org.streum.configrity.package$.<clinit>(package.scala)
            at org.streum.configrity.Configuration$.<init>(Configuration.scala:193)
            at org.streum.configrity.Configuration$.<clinit>(Configuration.scala)
            at io.clynamen.github.PolitoDownloader.Gui.ConfManager$.readConf(ConfManager.scala:19)
            at io.clynamen.github.PolitoDownloader.Gui.MainWindow$$anon$3.<init>(MainWindow.scala:54)
            at io.clynamen.github.PolitoDownloader.Gui.MainWindow$.delayedEndpoint$io$clynamen$github$PolitoDownloader$Gui$MainWindow$1(MainWindow.scala:53)
            at io.clynamen.github.PolitoDownloader.Gui.MainWindow$delayedInit$body.apply(MainWindow.scala:19)
            at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
            at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
            at scalafx.application.AppHelper.start(AppHelper.scala:32)
            at com.sun.javafx.application.LauncherImpl$8.run(Unknown Source)
            at com.sun.javafx.application.PlatformImpl$7.run(Unknown Source)
            at com.sun.javafx.application.PlatformImpl$6$1.run(Unknown Source)
            at com.sun.javafx.application.PlatformImpl$6$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at com.sun.javafx.application.PlatformImpl$6.run(Unknown Source)
            at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
            at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
            at com.sun.glass.ui.win.WinApplication.access$300(Unknown Source)
            at com.sun.glass.ui.win.WinApplication$4$1.run(Unknown Source)
            ... 1 more
    Caused by: java.lang.ClassNotFoundException: scala.util.parsing.combinator.RegexParsers
            at com.simontuffs.onejar.JarClassLoader.findClass(JarClassLoader.java:713)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at com.simontuffs.onejar.JarClassLoader.loadClass(JarClassLoader.java:630)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            ... 29 more

我认为这是一个奇怪的错误,因为该类应该在标准库中。我也尝试用程序集构建一个 jar 文件,这会产生同样的问题。

这是我的 build.sbt

import com.github.retronym.SbtOneJar._

name := "politodownloader"

version := "0.1.0"

//scalaVersion := "2.10.2"

scalaVersion := "2.11.2"

oneJarSettings

scalacOptions := Seq("-deprecation", "-unchecked", "-feature")

resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"


resolvers += "spray" at "http://repo.spray.io/"

libraryDependencies ++= Seq(
  //"org.scalatest" % "scalatest_2.10" % "2.0" % "test" withSources() withJavadoc(),
  //"org.scalacheck" % "scalacheck_2.10" % "1.10.0" % "test" withSources() withJavadoc(),
  "org.eintr.loglady" % "loglady_2.10" % "1.1.0",
  //  "net.sourceforge.htmlunit" % "htmlunit" % "2.15",
  "net.sourceforge.htmlunit" % "htmlunit" % "2.13",
  "org.jsoup" % "jsoup" % "1.7.2",
  "ch.qos.logback" % "logback-classic" % "1.1.2",
  "org.scalafx" % "scalafx_2.11" % "8.0.0-R4",
  "com.typesafe.akka" % "akka-actor_2.11" % "2.3.4",
  //"com.typesafe" % "config" % "1.2.1",
  "org.scala-lang" % "scala-library" % "2.11.2",
  "org.streum" % "configrity-core_2.10" % "1.0.0"
)

mainClass in Compile := Some("io.clynamen.github.PolitoDownloader.Gui.MainWindow")

mainClass in oneJar := Some("io.clynamen.github.PolitoDownloader.Gui.MainWindow")

initialCommands := "import io.clynamen.github.PolitoDownloader._"
4

1 回答 1

3

部分标准库在 2.11 中被打破。

对于 org.scala-lang.modules 组,有工件 scala-xml、scala-parser-combinators 等,每个都单独版本化。

好的,就是这样:

http://mvnrepository.com/artifact/org.scala-lang.modules/scala-parser-combinators_2.11/1.0.2

于 2014-08-08T15:36:10.440 回答