日安!请帮帮我。我启动了这个示例
sbt> run一切都好了,在那之后
sbt> package将构建jar文件,双击消息后:
Error: A JNI error has occured, please check your installation and try again.
Scala版本: 2.12.4。JVM:1.8.0_152。ScalaFX:8.0.102-R11
hello.scala:`
package hello
import scalafx.Includes._
import scalafx.application.JFXApp
import scalafx.application.JFXApp.PrimaryStage
import scalafx.scene.Scene
import scalafx.scene.paint.Color._
import scalafx.scene.shape.Rectangle
object HelloStage extends JFXApp {
stage = new JFXApp.PrimaryStage {
title.value = "Hello Stage"
width = 600
height = 450
scene = new Scene {
fill = LightGreen
content = new Rectangle {
x = 25
y = 40
width = 100
height = 100
fill <== when(hover) choose Green otherwise Red
}
}
}
}build.sbt:
name := "Scala"
organization := "scalafx.org"
version := "1.0.5"
scalaVersion := "2.12.4"
scalacOptions ++= Seq("-unchecked", "-deprecation", "-Xcheckinit", "-encoding", "utf8")
resourceDirectory in Compile := (scalaSource in Compile).value
libraryDependencies ++= Seq(
"org.scalafx" %% "scalafx" % "8.0.102-R11",)
addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full)
fork := true发布于 2017-10-28 10:09:09
这是一个Java classpath问题。当您尝试执行生成的JAR文件时,它找不到需要运行的jar文件。
尝试以下操作:
首先,将以下内容复制粘贴到project/plugins.sbt中:
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.5")这将加载sbt-assembly插件,该插件将创建一个包含所有依赖项的fat JAR文件。
其次,将您的build.sbt文件更改为以下内容:
name := "Scala"
organization := "scalafx.org"
version := "1.0.5"
scalaVersion := "2.12.4"
scalacOptions ++= Seq("-unchecked", "-deprecation", "-Xcheckinit", "-encoding", "utf8")
libraryDependencies += "org.scalafx" %% "scalafx" % "8.0.102-R11"
fork := true
mainClass in assembly := Some("hello.HelloStage")这简化了你最初拥有的东西。宏天堂编译器插件不是必需的,我还删除了稍微奇怪的resourceDirectory设置。
要创建fat JAR,请运行以下命令:
sbt
sbt> assembly您要查找的JAR文件很可能位于target/scala-2.12/Scala-assembly-1.0.5.jar。你现在应该可以走了.
或者,您可以使用add all the necessary files to your classpath。另一个可以帮助你做到这一点的插件(你可能不应该在sbt-assembly中使用它)是sbt-native-packager,它为你创建安装程序。然后,您可以安装您的应用程序并像运行常规应用程序一样运行它。
https://stackoverflow.com/questions/46970293
复制相似问题