2016-10-31 86 views
0

我正嘗試創建一個獨立的Java可執行文件來顯示WorldWind Globe並繼續運行到依賴項問題。下面是我的代碼:無法在獨立Java可執行文件中使用WorldWind

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); 
    } 
} 

這是Maven項目我的POM文件:

<?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> 

我能做到這一點的,沒有問題的NetBeans,但第二次我用窗簾插件Maven並在NetBeans之外運行可執行文件我收到以下錯誤:

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) 

任何想法爲什麼會發生這種情況?我認爲Shade Plugin將jar包內的依賴包打包,這樣它可以在IDE之外工作?任何幫助將不勝感激。我使用的世界風2.0和Java 8

+0

這是一箇舊項目! ^^如果我能夠編譯它,我很幸運,更別說用它作爲一個庫。 –

+0

是的,我知道這有點舊了,但它在我的公司仍然有很多或者更糟的用處。 – BlueMoose

回答

0

很多玩弄我可以使用下面的命令來調用獨立的可執行文件後:

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

此命令設置類路徑的庫文件夾包含所有必需的World Wind依賴罐。我還需要提取部分WorldWind jar中的dll,以便可以分別調用它們。我希望這能幫助一些有困難的人。

相關問題