maven-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Curtis Rueden <ctrue...@wisc.edu>
Subject Re: Maven Project: Multiple Artifacts for JNI Interface (.jar and .so)
Date Mon, 01 Apr 2013 18:00:39 GMT
Hi Patrick,

Did you look at the Maven SWIG Plugin?

   http://duns.github.com/maven-swig-plugin/

It works in conjunction with the NAR plugin:

   https://github.com/maven-nar/

> SWIG successfully creates the Java files
> and places them in the `src/main/java` directory.

Even if the SWIG plugin won't work for you (due to Android-specific issues
or whatever), generated source code should go into target/generated-sources
rather than src/main/java. And since you are doing it via antrun, you may
also need to use the Build Helper Maven Plugin to add the generated sources
directory as a second source folder.

> 1. The `jar` that is created doesn't contain any of the Java classes.
> The classes are being compiled, and I can see them in the
> target/classes directory, but they don't appear in the `jar`.

Can't help you with that one...

> 2. When the `jar` is deployed to my local repository, it gets renamed
> from a `jar` to an `so` because of the project packaging.

The "nar" packaging type of the NAR plugin is intended to address this
issue.

That's about the limit of my knowledge, though...

Regards,
Curtis


On Mon, Apr 1, 2013 at 12:49 PM, theisenp <theisenp+nabble@gmail.com> wrote:

> I'm using Maven to manage an Android project, and I've run into some
> trouble
> trying to handle a native library dependency.
>
> This is the general build strategy:
>
>  1. Use SWIG to generate both sides of a JNI interface to the native
> library
>  2. Use the Android NDK to package the C output from SWIG and the native
> library into an `so` shared library
>  3. Package the Java output from SWIG into an interface `jar` that other
> modules of my application can include
>
> <http://maven.40175.n5.nabble.com/file/n5752368/eo1v8.jpg>
>
> At the moment I'm trying to build both the `so` library and the interface
> `jar` from the same project. I'm aware that this breaks the Maven
> convention
> of 'one module, one artifact' and if there's a better way to organize the
> projects then I'd love to hear it. I've chosen to break the convention
> because both the `so` and the `jar` depend on the output from SWIG.
>
>
> ### SWIG ###
>
> The first task is to use SWIG to generate both the Java and C components of
> the JNI interface.  I'm using the `maven-antrun-plugin` to accomplish this:
>
>     <build>
>         ...
>         <plugin>
>             <artifactId>maven-antrun-plugin</artifactId>
>             <version>1.7</version>
>             <executions>
>                 <execution>
>                     <phase>generate-sources</phase>
>                     <goals>
>                         <goal>run</goal>
>                     </goals>
>                     <configuration>
>                        <target>
>                             <mkdir dir="${swig.java.directory}" />
>                             <exec executable="${swig.path}">
>                                 <arg value="-java" />
>                                 <arg value="-package" />
>                                 <arg value="${swig.java.package}" />
>                                 <arg value="-outdir" />
>                                 <arg value="${swig.java.directory}" />
>                                 <arg
> value="${swig.source.directory}/native.i" />
>                             </exec>
>                         </target>
>                     </configuration>
>                 </execution>
>             </executions>
>         </plugin>
>         ...
>     </build>
>
> This works well, taking my SWIG interface file `native.i` and generating
> the
> associated Java classes and a `native_wrap.c` file.
>
>
> ### Native Library ###
>
> To handle the native library creation, I've set the project packaging to
> `so` and included the `android-maven-plugin`:
>
>     <packaging>so</packaging>
>
>     <build>
>         ...
>         <plugin>
>             <groupId>com.jayway.maven.plugins.android.generation2</groupId>
>             <artifactId>android-maven-plugin</artifactId>
>             <extensions>true</extensions>
>         </plugin>
>         ...
>     </build>
>
> This also works great, and combined with my `Android.mk` file, it generates
> the native `so` library.
>
>
> ### Jar ###
>
> This is where I run into trouble. SWIG successfully creates the Java files
> and places them in the `src/main/java` directory. However, I'm not sure how
> to bundle them up into a `jar` and deploy them to the repository without
> changing the project packaging. My first instinct was to use the
> `maven-jar-plugin` to manually package up the Java classes:
>
>     <build>
>         ...
>         <plugin>
>             <artifactId>maven-jar-plugin</artifactId>
>                 <executions>
>                 <execution>
>                     <id>interface</id>
>                     <phase>package</phase>
>                     <goals>
>                         <goal>jar</goal>
>                     </goals>
>                     <configuration>
>                         <includes>
>
> <include>${project.build.outputDirectory}</include>
>                         </includes>
>                     </configuration>
>                 </execution>
>             </executions>
>         </plugin>
>         ...
>     </build>
>
> However, this doesn't quite give me the behavior I want.  There are two
> problems:
>
>  1. The `jar` that is created doesn't contain any of the Java classes. The
> classes are being compiled, and I can see them in the target/classes
> directory, but they don't appear in the `jar`.
>  2. When the `jar` is deployed to my local repository, it gets renamed from
> a `jar` to an `so` because of the project packaging.
>
> Thoughts?
>
>
>
> --
> View this message in context:
> http://maven.40175.n5.nabble.com/Maven-Project-Multiple-Artifacts-for-JNI-Interface-jar-and-so-tp5752368.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message