【问题标题】:Runnable JAR file doesn't run after export in Eclipse在 Eclipse 中导出后可运行的 JAR 文件不运行
【发布时间】:2023-03-19 03:33:01
【问题描述】:

我有以下层次结构:

当我将项目导出为可运行的 JAR 文件(32 位平台)时,该文件 已成功创建,但是当我尝试运行它时,什么也没有发生 - 操作系统没有响应(Windows 7 Pro)。

为什么我不能运行 jar 文件?

谢谢

编辑:

C:\1>java -jar ex3.jar
Catched FileNotFoundException: C:\1\ex3-natives-windows-i586.jar (The system can
not find the file specified), while TempJarCache.bootstrapNativeLib() of jar:fil
e:/C:/1/ex3-natives-windows-i586.jar!/ (file:/C:/1/ + ex3-natives-windows-i586.j
ar)
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: no gluege
n-rt in java.library.path
        at java.lang.ClassLoader.loadLibrary(Unknown Source)
        at java.lang.Runtime.loadLibrary0(Unknown Source)
        at java.lang.System.loadLibrary(Unknown Source)
        at com.jogamp.common.jvm.JNILibLoaderBase.loadLibraryInternal(JNILibLoad
erBase.java:442)
        at com.jogamp.common.jvm.JNILibLoaderBase.access$000(JNILibLoaderBase.ja
va:59)
        at com.jogamp.common.jvm.JNILibLoaderBase$DefaultAction.loadLibrary(JNIL
ibLoaderBase.java:90)
        at com.jogamp.common.jvm.JNILibLoaderBase.loadLibrary(JNILibLoaderBase.j
ava:328)
        at com.jogamp.common.os.DynamicLibraryBundle$GlueJNILibLoader.loadLibrar
y(DynamicLibraryBundle.java:390)
        at com.jogamp.common.os.Platform.loadGlueGenRTImpl(Platform.java:251)
        at com.jogamp.common.os.Platform.access$000(Platform.java:57)
        at com.jogamp.common.os.Platform$1.run(Platform.java:186)
        at com.jogamp.common.os.Platform$1.run(Platform.java:183)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.jogamp.common.os.Platform.<clinit>(Platform.java:183)
        at javax.media.opengl.GLProfile.<clinit>(GLProfile.java:82)
        at javax.media.opengl.awt.GLCanvas.<init>(GLCanvas.java:246)
        at javax.media.opengl.awt.GLCanvas.<init>(GLCanvas.java:196)
        at javax.media.opengl.awt.GLCanvas.<init>(GLCanvas.java:186)
        at WorldController.<init>(WorldController.java:119)
        at WorldController$1.run(WorldController.java:478)
        at java.awt.event.InvocationEvent.dispatch(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$200(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Sour
ce)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)

C:\1>

更新:

C:\>
C:\>java -jar ex3.jar
Exception in thread "main" java.lang.IllegalAccessException: Class org.eclipse.j
dt.internal.jarinjarloader.JarRsrcLoader can not access a member of class WorldC
ontroller with modifiers "public static"
        at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)
        at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(Unknown Sour
ce)
        at java.lang.reflect.AccessibleObject.checkAccess(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:58)

C:\>

【问题讨论】:

  • 使用java -jar &lt;jar file name&gt;在命令提示符下运行jar并检查是否有异常。
  • @Karthikeyan:我在帖子中添加了它,有例外,但据说丢失的文件在那里。
  • 当您在 Eclipse 中导出可运行的 jar 时,使用“将所需的库打包到 JAR”然后尝试。
  • @Karthikeyan:和之前一样,输出附上。
  • 你的类中没有主要方法。

标签: java eclipse jar export


【解决方案1】:

您似乎接到了非法电话。这意味着您尝试调用不允许调用的方法。 (参考您更新的编辑)

您的错误表明您要使用修饰符 public static 执行方法。静态方法必须使用类名而不是对象调用:

SomeClass.staticMethodCall();

以下是错误的:

SomeClass sc = new SomeClass();
sc.staticMethodCall();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-13
    • 2013-02-21
    • 2017-05-13
    • 1970-01-01
    • 2012-12-06
    • 1970-01-01
    相关资源
    最近更新 更多