Eclipse生成的Runnable jar文件不会执行? [英] Runnable jar file generated by Eclipse wont execute?

查看:139
本文介绍了Eclipse生成的Runnable jar文件不会执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Eclipse的Export - > Java - > Runnable Jar文件功能生成了一个非常简单的runnable jar文件。我的HelloWorld类看起来像这样:

  import javax.swing.JFrame; 
public class HWorld extends JFrame {
public static void main(String [] args){
new HWorld();
}
public HWorld(){
this.setSize(200,100);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setTitle(Hello World!);
this.setVisible(true);
}
}

现在,生成.jar文件后,它运行从命令行使用命令java -jar HWorld.jar



但是,当我尝试自己执行jar(这应该是应该工作)得到以下错误,我不知道为什么:

  E:\Eclipse\workspace> HWorld.jar 
线程main中的异常java.lang.NoClassDefFoundError:E:\Eclipse\workspace\HWorld / jar
导致:java.lang.ClassNotFoundException:E:\Eclipse\workspace\在java.net.URLClassLoader中的$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ findClass(URLClassLoader.java:188)
在java.lang.ClassLoader.loadClass(ClassLoader.java:307)
在sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:301)
在java.lang.ClassLoader.load Class(ClassLoader.java:252)
在java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
找不到主类:E:\Eclipse\workspace\HWorld。罐。程序将退出。

我的清单如下所示:

  Manifest-Version:1.0 
Rsrc-Class-Path:./
Class-Path:。
Rsrc-Main-Class:HWorld
主类:org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader

唯一看起来真的很讽刺的是这个(因为.jar不是一个.class):

 找不到主类:E:\Eclipse\workspace\HWorld.jar 

寻找想法或想法甚至答案!我尽量给予尽可能多的信息,希望有一个高质量的答案。这个线程意味着它应该工作,但不回答我的问题: http:// forums.oracle.com/forums/thread.jspa?threadID=2152988 。任何人都可以在Eclipse中尝试吗?

解决方案

在这个意义上,Jars是永远不可执行的。这个jar是好的:

  java -jar YOURJAR.jar 
/ pre>

更新您提供的回溯是奇怪的。看来,Windows决定继续使用一些版本的Java启动你的jar,但是在一个类名的地方传递一个路径名。我不知道这个故事是什么。


I generated a very simple runnable jar file using Eclipse's "Export-->Java-->Runnable Jar File" function. My HelloWorld class looks like this:

import javax.swing.JFrame;
public class HWorld extends JFrame {
  public static void main(String[] args) {
    new HWorld();
  }
  public HWorld() {
    this.setSize(200, 100);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setTitle("Hello World!");
    this.setVisible(true);
  }
}

Now, after generating the .jar file , it runs fine from the command line using the command "java -jar HWorld.jar"

But, when I try to execute the jar on its own (which supposedly should work) I get the following error and I don't know why:

E:\Eclipse\workspace>HWorld.jar
Exception in thread "main" java.lang.NoClassDefFoundError: E:\Eclipse\workspace\HWorld/jar
Caused by: java.lang.ClassNotFoundException: E:\Eclipse\workspace\HWorld.jar
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: E:\Eclipse\workspace\HWorld.jar.  Program will exit.

My manifest looks like this:

Manifest-Version: 1.0
Rsrc-Class-Path: ./
Class-Path: .
Rsrc-Main-Class: HWorld
Main-Class: org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader

The only thing that looks really fishy to me is this (since a .jar is not a .class):

Could not find the main class: E:\Eclipse\workspace\HWorld.jar

Looking for ideas or thoughts or even an answer! I tried to give as much info as possible in hope of a quality answer. This thread implies that it should work but doesn't answer my question: http://forums.oracle.com/forums/thread.jspa?threadID=2152988 . Can anyone else try it in their Eclipse?

解决方案

Jars are never 'executable' in this sense. What this jar is good for is:

java -jar YOURJAR.jar

update the backtrace you supplied is bizarre. It appears that Windows decided to go ahead and launch your jar with some version of Java, but pass it a pathname in the place of a class name. I don't know what the story is with that.

这篇关于Eclipse生成的Runnable jar文件不会执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆