Netbeans Maven, Build native jar with dependencies

1,019 views
Skip to first unread message

Matt Zygowicz

unread,
Dec 23, 2013, 9:17:48 AM12/23/13
to jz...@googlegroups.com

Currently I have a Netbeans Maven project using BioJava and JZY3D dependencies. I believe JZY3D to be the culprit and overall problem.

What is happening?
 Currently I have a jar (NEVBLAST-1.0-SNAPSHOT-jar-with-dependencies.jar) and this currently runs. When the program gets to the point where it has to graph. The line it breaks is a JZY3D line: (AWTChartComponentFactory.newChart(Quality.Advanced, Toolkit.awt);). On runtime once the program gets to graphing it gives this error:

Catched FileNotFoundException: /home/ziggy/Desktop/NEVBLAST/target/NEVBLAST-1.0-SNAPSHOT-jar-with-dependencies-natives-linux-amd64.jar (No such file or directory), while TempJarCache.bootstrapNativeLib() of jar:file:/home/ziggy/Desktop/NEVBLAST/target/NEVBLAST-1.0-SNAPSHOT-jar-with-dependencies-natives-linux-amd64.jar!/ (file:/home/ziggy/Desktop/NEVBLAST/target/ + NEVBLAST-1.0-SNAPSHOT-jar-with-dependencies-natives-linux-amd64.jar)

Is there a way to build these OS specific dependencies through maven? This project is my first working with maven and I have hit a complete standstill and do not know what to do.

Thanks for any and all input!

Current Code: You can see current code base at: code.google.com/p/nev-blast/source/checkout Let me know if there are any problems running the program. The program is configured to startoff with test data so all you have to do is hit submit to see the graphs (or where it is breaking...Note it is breaking in the class: Grapher.java)

Martin Pernollet

unread,
Dec 24, 2013, 7:57:19 AM12/24/13
to Jzy3d
Hi,
Looks like JOGL fails to load native jars.
I remember from an old JOGL discussion (1 or 2 years?) that loading native libraries (bundled in jars named by the target OS) will fail if you bundle jogl jars into one single super jar for your whole application.
Is that your case? 


2013/12/23 Matt Zygowicz <golds...@gmail.com>

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes Jzy3d.
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse jzy3d+un...@googlegroups.com.
Pour plus d'options, visitez le site https://groups.google.com/groups/opt_out .

Matt Zygowicz

unread,
Dec 24, 2013, 8:42:59 AM12/24/13
to jz...@googlegroups.com
Ahh So the problem is with JOGL, which makes sense for it fails in the charting phase.  The Jar is built using maven and maven is told to include dependencies.  Is there a workaround for this that you know of or is my pom.xml simply incorrect?  Thanks for any help towards this!

Nils Hoffmann

unread,
Dec 27, 2013, 4:53:59 AM12/27/13
to jz...@googlegroups.com
Hi Matt!
This is definitely an issue with the native library loading of jogl.
Instead of the assembly plugin, you could try to use the appassembler plugin in combination with the assembly plugin:

http://mojo.codehaus.org/appassembler/appassembler-maven-plugin/index.html

Simply add the following to your pom and comment the assembly plugin.

             <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <descriptors>
                        <descriptor>src/assembly/assembly.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>  <!-- this is used for inheritance merges -->
                        <phase>verify</phase>  <!-- bind to the verify phase, to execute after package phase -->
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>appassembler-maven-plugin</artifactId>
                <version>1.7</version>
                <configuration>
                    <programs>
                        <program>
                            <mainClass>group4.nevblast.Main</mainClass>
                            <id>nevblast</id>
                        </program>
                    </programs>
                    <repositoryName>lib</repositoryName>
                    <repositoryLayout>flat</repositoryLayout>
                    <assembleDirectory>${project.build.directory}/${project.artifactId}</assembleDirectory>
                </configuration>
                <executions>
                    <execution>
                        <id>prepare-assembly</id>  <!-- this is used for inheritance merges -->
                        <phase>package</phase>  <!-- bind to the package phase -->
                        <goals>
                            <goal>assemble</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Then create the file src/assembly/assembly.xml and add the following content:

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>bin</id>
    <formats>
        <format>zip</format>
    </formats>
    <fileSets>
        <fileSet>
            <directory>${project.build.directory}/${project.artifactId}</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>/**</include>
            </includes>
            <excludes>
                <exclude>bin/*</exclude>
            </excludes>
        </fileSet>
        <fileSet>
            <directory>${project.build.directory}/${project.artifactId}/bin</directory>
            <lineEnding>keep</lineEnding>
            <useDefaultExcludes>true</useDefaultExcludes>
            <outputDirectory>bin</outputDirectory>
            <includes>
                <include>*</include>
            </includes>
            <fileMode>744</fileMode>
        </fileSet>
    </fileSets>
</assembly>


The appassembler plugin will create a folder "target/NEVBLAST" below which you will find a 'bin' and 'lib' directory. The first one contains launch scripts for your
program, the second one contains all your project's jar dependencies.
The assembly plugin then creates a zip distribution of your program at target/NEVBLAST-1.0-SNAPSHOT-bin.zip which contains your zipped program and the launch scripts.

JOGL generally has problems with shaded/one/uber-jars, actually, not only JOGL because stuffing everything into on big jar can have side effects if multiple files exist at the same
locations and need to be merged. AFAIK, the maven-shade plugin is the only packager that provides a mechanism to deal with such problems, but it interferes with the way JOGL locates the
correct native libraries via the MANIFEST.MF in the respective resource jar files.

Hope it helps!

Nils

Matt Zygowicz

unread,
Jan 5, 2014, 4:01:19 PM1/5/14
to jz...@googlegroups.com
Hello Nils,

I would just like to thank you for your help in this problem, and sorry for the late reply.
I wanted to say that your solution worked flawlessly and I found it extremely helpful.

Thanks,
Matt
Reply all
Reply to author
Forward
0 new messages