Skip to content

Commit

Permalink
Better way to load javafx library into the class path
Browse files Browse the repository at this point in the history
Although this is a hack, it seems like a well tested hack (based on
Stack overflow answers). And it can be removed when Java 8 is released.
  • Loading branch information
hrj committed Nov 29, 2013
1 parent cbe1b44 commit 1063607
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/main/scala/co/uproot/abandon/Main.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
package co.uproot.abandon

import java.net.{URL, URLClassLoader}

object Main extends App {

if(args.headOption.getOrElse("") equals "-g") {
ensureJFXIsAvailable()
AbandonUI.main(args.tail)
} else {
AbandonApp.main(args)
}

def ensureJFXIsAvailable() {
try {
Class.forName("javafx.event.EventTarget")
} catch {
case e:java.lang.ClassNotFoundException =>
val javaHome = System.getProperty("java.home")
addSoftwareLibrary(javaHome, "lib", "jfxrt.jar")
case e: java.lang.NoClassDefFoundError =>
val javaHome = System.getProperty("java.home")
addSoftwareLibrary(javaHome, "lib", "jfxrt.jar")
}
}

def addSoftwareLibrary(filePath:String*) = {
val file = new java.io.File(filePath.mkString(java.io.File.separator))
val method = classOf[URLClassLoader].getDeclaredMethod("addURL", classOf[URL]);
method.setAccessible(true);
method.invoke(ClassLoader.getSystemClassLoader(), file.toURI.toURL);
}
}

0 comments on commit 1063607

Please sign in to comment.