Skip to content

Instantly share code, notes, and snippets.

@horus
Created January 16, 2015 11:12
Show Gist options
  • Select an option

  • Save horus/52e2c81ee364e69c26e8 to your computer and use it in GitHub Desktop.

Select an option

Save horus/52e2c81ee364e69c26e8 to your computer and use it in GitHub Desktop.
java-bridge JNI/Haskell example
import Foreign.Java
main :: IO ()
main = do
initJava ["-Djava.class.path=/home/horus/test"]
runJava $ do
Just testClass <- getClass "Test"
Just systemClass <- getClass "java.lang.System"
Just printStreamClass <- getClass "java.io.PrintStream"
Just outField <- getStaticField systemClass "out" (object "java.io.PrintStream")
Just out <- readStaticField outField
println <- printStreamClass `bindMethod` "println" ::= string --> void
getTimeFromFile <- testClass `bindStaticMethod` "getTimeFromFile" ::= string --> long
result <- getTimeFromFile "/home/tomcat/logs/customlog.log.2015-01-11-05-01"
println out ("Hello from JVM: " ++ show result)
-- Hello from JVM: 1420923660000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment