Created
January 16, 2015 11:12
-
-
Save horus/52e2c81ee364e69c26e8 to your computer and use it in GitHub Desktop.
java-bridge JNI/Haskell example
This file contains hidden or 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
| 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