-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better way to load javafx library into the class path
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
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |