jvm

Call JVM methods from Haskell. http://github.com/tweag/inline-java/tree/master/jvm#readme

Version on this page:0.2.2
LTS Haskell 9.14:0.2.2
Stackage Nightly 2017-07-25:0.2.2
Latest on Hackage:0.3.0
BSD3 licensed by Tweag I/O
Maintained by m@tweag.io

Module documentation for 0.2.2

jvm: Call any JVM function from Haskell

jvm on Stackage LTS jvm on Stackage Nightly

This package enables calling any JVM function from Haskell. If you'd like to call JVM methods using Java syntax and hence get the Java compiler to scope check and type check all your foreign calls, see inline-java, which builds on top of this package.

Example

Graphical Hello World using Java Swing:

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}

import Data.Text (Text)
import Language.Java

newtype JOptionPane = JOptionPane (J ('Class "javax.swing.JOptionPane"))
instance Coercible JOptionPane ('Class "javax.swing.JOptionPane")

main :: IO ()
main = withJVM [] $ do
    message <- reflect ("Hello World!" :: Text)
    callStatic
      (classOf (undefined :: JOptionPane))
      "showMessageDialog"
      [JObject nullComponent, JObject (upcast message)]
  where
    nullComponent :: J ('Class "java.awt.Component")
    nullComponent = jnull
comments powered byDisqus