The inline-java package

[ Tags: bsd3, ffi, java, jvm, library ] [ Propose Tags ]

Please see README.md.


[Skip to Readme]

Properties

Versions 0.1, 0.5, 0.5.1, 0.6, 0.6.1, 0.6.2, 0.6.3, 0.6.4, 0.6.5, 0.7.0
Change log CHANGELOG.md
Dependencies base (>4.9.0.0 && <5), bytestring (>=0.10), Cabal (>=1.24.2), directory (>=1.2), filepath (>=1), ghc (>=8.0.2 && <8.3), jni (>=0.4), jvm (>=0.3), language-java (>=0.2), mtl (>=2.2.1), process (>=1.2), template-haskell (>=2.10), temporary (>=1.2), text (>=1.2) [details]
License BSD3
Copyright 2015-2016 EURL Tweag.
Author Tweag I/O
Maintainer m@tweag.io
Category FFI, JVM, Java
Home page http://github.com/tweag/inline-java#readme
Source repository head: git clone https://github.com/tweag/inline-java
Uploaded Thu Aug 31 14:44:15 UTC 2017 by FacundoDominguez
Distributions LTSHaskell:0.6.5, NixOS:0.7.0
Downloads 442 total (31 in the last 30 days)
Rating 0.0 (0 ratings) [clear rating]
  • λ
  • λ
  • λ
Status Docs not available [build log]
All reported builds failed as of 2017-08-31 [all 3 reports]
Hackage Matrix CI

Modules

  • Language
    • Java
      • Language.Java.Inline
        • Language.Java.Inline.Cabal
        • Language.Java.Inline.Plugin

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for inline-java-0.7.0

[back to package description]

inline-java: Call any JVM function from Haskell

CircleCI

NOTE 1: you'll need GHC >= 8.0.2 to compile and use this package.

NOTE 2: you'll need Stack HEAD (future v1.6) to compile with GHC >= 8.2.1. It is recommended to stick to GHC-8.0.2 for now.

The Haskell standard includes a native foreign function interface (FFI). Using it can be a bit involved and only C support is implemented in GHC. inline-java lets you call any JVM function directly, from Haskell, without the need to write your own foreign import declarations using the FFI. In the style of inline-c for C and inline-r for calling R, inline-java lets you name any function to call inline in your code. It is implemented on top of the jni and jvm packages.

Example

Graphical Hello World using Java Swing:

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -fplugin=Language.Java.Inline.Plugin #-}
module Main where

import Data.Text (Text)
import Language.Java
import Language.Java.Inline

main :: IO ()
main = withJVM [] $ do
    message <- reflect ("Hello World!" :: Text)
    [java| {
      javax.swing.JOptionPane.showMessageDialog(null, $message);
      } |]

Building it

Requirements:

  • the Stack build tool (version 1.2 or above);
  • either, the Nix package manager,
  • or, OpenJDK, Gradle and Spark (version 1.6) installed from your distro.

On OS X, you'll need to install the Legacy Java SE 6 runtime when prompted, even when using Nix.

To build:

$ stack build

You can optionally get Stack to download a JDK in a local sandbox (using Nix) for good build results reproducibility. This is the recommended way to build inline-java. Alternatively, you'll need it installed through your OS distribution's package manager for the next steps (and you'll need to tell Stack how to find the JVM header files and shared libraries).

To use Nix, set the following in your ~/.stack/config.yaml (or pass --nix to all Stack commands, see the Stack manual for more):

nix:
  enable: true

Debugging

The generated java output can be dumped to stderr by passing to GHC

-fplugin-opt=Language.Java.Inline.Plugin:dump-java

If -ddump-to-file is in effect (as when using stack), the java code is dumped to <module>.dump-java instead.

License

Copyright (c) 2015-2016 EURL Tweag.

All rights reserved.

inline-java is free software, and may be redistributed under the terms specified in the LICENSE file.

Sponsors

         Tweag I/O              LeapYear

inline-java is maintained by Tweag I/O.

Have questions? Need help? Tweet at @tweagio.