我有一个应该创建一个可运行的jar文件的sbt项目。正确创建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._"
答案 0 :(得分:3)
std lib的部分内容在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