Skip to content

Instantly share code, notes, and snippets.

@huynhjl
Created January 22, 2011 09:25
Show Gist options
  • Save huynhjl/791007 to your computer and use it in GitHub Desktop.
Save huynhjl/791007 to your computer and use it in GitHub Desktop.
jansi.dll already loaded in another classloader
// scala -cp "jcl-core-2.2.2.jar;log4j-1.2.16.jar"
// http://sourceforge.net/projects/jcloader/files/jcl2/org/xeustechnologies/jcl/2.2.2/jcl-core-2.2.2.jar/download
// see http://jcloader.sourceforge.net/gettingstarted.html
import org.xeustechnologies.jcl._
import java.lang.reflect.Method
// jline2
//val t = new jline.WindowsTerminal
//t.getWidth
// trying in a classloader:
def jline2_getWidth(path:String) = {
import scala.util.control.Exception.allCatch
val jcl = new JarClassLoader()
jcl.add(path)
val factory = JclObjectFactory.getInstance()
val winTerminal = factory.create(jcl, "jline.WindowsTerminal")
val method = winTerminal.getClass.getMethod("getWidth")
allCatch either { method.invoke(winTerminal) } match {
case Left(ex) => ex.toString + " " + ex.getCause.getMessage
case Right(obj) => obj.toString
}
}
jline2_getWidth("""C:\jlh\code\other\scala-2.9.0.r24045\lib\jline.jar""")
// res0: java.lang.String = java.lang.reflect.InvocationTargetException
// Could not load library. Reasons:
// [no jansi in java.library.path,
// Native Library C:\Users\jlh\AppData\Local\Temp\jansi.dll already loaded in another classloader]
// vim: set ts=2 sw=2 et:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment