简体   繁体   中英

Unable to use WorldWind in Standalone Java Executable

I am trying to create a stand alone Java executable to display the WorldWind Globe and keep running into dependency issues. Below is my code:

package com.mycompany.testmaven;

import gov.nasa.worldwind.BasicModel;
import gov.nasa.worldwind.Configuration;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.awt.WorldWindowGLCanvas;
import gov.nasa.worldwind.layers.Layer;
import gov.nasa.worldwind.render.Offset;
import gov.nasa.worldwind.util.layertree.LayerTree;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class WorldWindGlobe
{
    public static void main(String[] args)

    {
        Layer graticuleLayer = null;
        WorldWindowGLCanvas worldWindCanvas = new WorldWindowGLCanvas();
        worldWindCanvas.setModel(new BasicModel());

            // Update layer panel
        final LayerTree layerTree = new LayerTree(new Offset(20d, 160d, AVKey.PIXELS, AVKey.INSET_PIXELS));
        layerTree.getModel().refresh(worldWindCanvas.getModel().getLayers());


        //build Java swing interface
        JPanel panel = new JPanel();
                panel.add(worldWindCanvas);

                JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(worldWindCanvas);
        frame.setSize(800,600);
        frame.setVisible(true);
    }
}

This is my pom file for the Maven Project:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany</groupId>
    <artifactId>TestMaven</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
 <dependencies>
<dependency>
    <groupId>gov.nasa</groupId>
    <artifactId>worldwind</artifactId>
    <version>2.0.0</version>
</dependency>
<dependency>
    <groupId>worldwind.jogl</groupId>
    <artifactId>jogl-all</artifactId>
    <version>2.0.0</version>
</dependency>
<dependency>
    <groupId>worldwind.gluegen</groupId>
    <artifactId>gluegen-rt</artifactId>
    <version>2.0.0</version>
</dependency>
  </dependencies>
  <build>
        <plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.4.3</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <mainClass>com.mycompany.testmaven.WorldWindGlobe</mainClass>
                </transformer>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin>
  </plugins>
  </build>

</project>

I am able to do it in NetBeans with no issues, but the second I use the Shade Plugin for Maven and run the executable outside of NetBeans I get the following errors:

Catched FileNotFoundException: C:\Users\User\Documents\NetBeansProjects\TestMaven\target\TestMaven-1.0-SNAPSHOT-natives-windows-amd64.jar (The system cannot find the file specified), while addNativeJarLibsImpl(classFromJavaJar class com.jogamp.common.os.Platform, classJarURI jar:file:/C:/Users/User/Documents/NetBeansProjects/TestMaven/target/TestMaven-1.0-SNAPSHOT.jar!/com/jogamp/common/os/Platform.class, nativeJarBaseName TestMaven-1.0-SNAPSHOT-natives-windows-amd64.jar): [ file:/C:/Users/User/Documents/NetBeansProjects/TestMaven/target/TestMaven-1.0-SNAPSHOT.jar -> file:/C:/Users/User/Documents/NetBeansProjects/TestMaven/target/ ] + TestMaven-1.0-SNAPSHOT-natives-windows-amd64.jar -> slim: jar:file:/C:/Users/User/Documents/NetBeansProjects/TestMaven/target/TestMaven-1.0-SNAPSHOT-natives-windows-amd64.jar!/
Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library: C:\Users\User\Documents\NetBeansProjects\TestMaven\target\gluegen-rt.dll
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.load0(Unknown Source)
    at java.lang.System.load(Unknown Source)
    at com.jogamp.common.jvm.JNILibLoaderBase.loadLibraryInternal(JNILibLoaderBase.java:551)
    at com.jogamp.common.jvm.JNILibLoaderBase.access$000(JNILibLoaderBase.java:64)
    at com.jogamp.common.jvm.JNILibLoaderBase$DefaultAction.loadLibrary(JNILibLoaderBase.java:96)
    at com.jogamp.common.jvm.JNILibLoaderBase.loadLibrary(JNILibLoaderBase.java:414)
    at com.jogamp.common.os.DynamicLibraryBundle$GlueJNILibLoader.loadLibrary(DynamicLibraryBundle.java:388)
    at com.jogamp.common.os.Platform$1.run(Platform.java:209)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.jogamp.common.os.Platform.<clinit>(Platform.java:179)
    at javax.media.opengl.GLProfile.<clinit>(GLProfile.java:83)
    at gov.nasa.worldwind.Configuration.getMaxCompatibleGLProfile(Unknown Source)
    at gov.nasa.worldwind.Configuration.getRequiredGLCapabilities(Unknown Source)
    at gov.nasa.worldwind.awt.WorldWindowGLCanvas.<init>(Unknown Source)
    at com.mycompany.testmaven.WorldWindGlobe.main(WorldWindGlobe.java:31)

Any ideas why this is happening? I thought the Shade Plugin packages the dependencies inside the jar so it can work outside of an IDE? Any help would be greatly appreciated. I am using WorldWind 2.0 and Java 8.

After a lot of playing around I was able to call the standalone executable using the following command:

java -cp ".;lib/WorldWIndExecutable.jar;lib/*;" com.mycompany.MainClass

This command sets the class path to a libraries folder containing all the necessary World Wind dependency jars. I also needed to have the dlls in some of the WorldWind jars extracted so they can be called separately. I hope this helps out some people having trouble.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM