Skip to content

joprice/sbt-jni

Repository files navigation

sbt-jni

Circle CI

Codacy Badge

Download

Sbt plugin for projects with jni sources.

On compile, the jniCompile task will be run. It first runs the jniJavah task, which generates JNI headers. Headers generated for jni classes will end up in jniHeadersPath, which defaults to target/native/include. The final library will be in jniBinPath, which defaults to target/native/bin.

See src/sbt-test/sbt-jni/basic for an example project.

Install

resolvers += Resolver.url("joprice-sbt-plugins", url("https://dl.bintray.com/content/joprice/sbt-plugins"))(Resolver.ivyStylePatterns)

addSbtPlugin("io.github.joprice" % "sbt-jni" % "0.2.0")

Testing

Run scripted to sbt tests.

Usage

Native sources should be placed in jniNativeSources, which defaults to src/main/native.

sbt-jni is an AutoPlugin, but is must be enabled explicitly.

enablePlugins(JniPlugin)

// this will be the name that you call `System.loadLibrary` with, prefixed with "lib"
jniLibraryName := "libMyApp"

jniGccFlags ++= Seq("-lpthread")

// defaults to gcc
jniNativeCompiler := "g++"

jniNativeClasses := Seq(
  "com.myapp.ClassWithJniCode"
)

Known Issues

  • This plugin uses javah, which was removed from newer jdk versions. It will have to be updated to use javac -h to support the latest jdks.