How to use jnaerator in a sbt project

431 views Asked by At

I work on a Scala project that uses c++ code, using sbt. Once compiled, this c++ code is imported into Scala through Java code that uses jna.

Now, currently the Java wrapper are manually written, and I like to automatize this. I've found jnaerator that can do that, but I don't know how I should use it in sbt.

I see two general approaches:

  1. use command line, such as java -jar jnaerator ... but I don't know how to setup such command line task in sbt? Also, I would need to know the typical project structure to follow: where to output the jna generated code?
  2. Use jnaerator maven plugin through sbt, if it is possible?
1

There are 1 answers

2
marios On BEST ANSWER

This might take some iteration until we get it do what you need.

For the first approach, here is how you can run custom system command on sbt (you essentially solve this using Scala code). Add the following to your build.sbt file:

lazy val runJnaerator= taskKey[Unit]("This task generates libraries from native code")

runJnaerator := {
    import sys.process._
    Seq("java" , "-jar", "jnaerator", "..." ).!
}

To execute:

>sbt runJnaerator

Now the question is where do you need these files files to go? Finally, how do you want to invoke everything?