找不到主类

发布于 2025-01-04 03:28:40 字数 1052 浏览 2 评论 0原文

好的,所以我一直在尝试制作可执行的 jar 文件。它使用命令“java -jar bybys.jar”运行,但是当我尝试使用 Enter 运行它时,它给我一个错误“找不到主类 bardejov.Image。程序将退出。”

这是清单:(

Manifest-Version: 1.0
Created-By: 1.7.0_02 (Oracle Corporation)
Main-Class: bardejov.Image 

是的,我使用了新行)

编译 jar 文件时,我尝试了与目录的所有可能组合,我不知道问题出在哪里。我使用 - C:\Java\2D>jar cfm bybys.jar Manifest.txt bardejov/Image.class bardejov/Board.class bardejov/*jpg

目录是:

META-INF/
META-INF/MANIFEST.MF
bardejov/Image.class
bardejov/Board.class
bardejov/siknius.jpg

和主类:

package bardejov;

import javax.swing.JFrame;


public class Image extends JFrame {

public Image() {

    add(new Board());

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(477, 530);
    setLocationRelativeTo(null);
    setTitle("Siknius");
    setVisible(true);
    setResizable(false);
}

public static void main(String[] args) {
    new Image();
}
}

如何使固定?

更新

我修复了它。问题是我没有安装最新的 JRE。

Okay, so I've been trying to make and executable jar file. It runs with the command "java -jar bybys.jar", but when i try to run it with enter it gives me an error "Could not find the main class bardejov.Image. Program will exit."

Here's the manifest :

Manifest-Version: 1.0
Created-By: 1.7.0_02 (Oracle Corporation)
Main-Class: bardejov.Image 

(yes i used a new line)

When compiling the jar file I tried every possible combination with the directory, I don't know where the problem is. I used - C:\Java\2D>jar cfm bybys.jar Manifest.txt bardejov/Image.class bardejov/Board.class bardejov/*jpg

The directory is:

META-INF/
META-INF/MANIFEST.MF
bardejov/Image.class
bardejov/Board.class
bardejov/siknius.jpg

And the main class:

package bardejov;

import javax.swing.JFrame;


public class Image extends JFrame {

public Image() {

    add(new Board());

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(477, 530);
    setLocationRelativeTo(null);
    setTitle("Siknius");
    setVisible(true);
    setResizable(false);
}

public static void main(String[] args) {
    new Image();
}
}

How to fix?

UPDATE

I fixed it. The problem was I didin't have the newest JRE installed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

调妓 2025-01-11 03:28:40

Manifest.txt 中类的名称后面有一个额外的空格字符。错误消息暗示了这一点:

Could not find the main class bardejov.Image .
                                            ^^

There's an extra space character after the name fof the class in your Manifest.txt. This is hinted by the error message:

Could not find the main class bardejov.Image .
                                            ^^
软甜啾 2025-01-11 03:28:40

问题实际上似乎是 jar 不包含目录 bardejov 的条目;它仅包含目录中的文件条目。您可以在列表中看到这一点;看看如何有 bardejov 的条目。创建 jar 文件时,必须告诉 jar 包含该目录,而不仅仅是其中的文件:

jar cfm bybys.jar Manifest.txt bardejov

The problem actually appears to be that the jar doesn't contain an entry for the directory bardejov; it contains only entries for the files in the directory. You can see this in your listing; see how there's an entry for bardejov. When you create the jar file, you have to tell jar to include the directory, not just the files in it:

jar cfm bybys.jar Manifest.txt bardejov
渡你暖光 2025-01-11 03:28:40

从 Java 6 开始,您可以使用 jar 命令指定入口点。以下命令应该为您的应用程序创建一个可执行的 jar 文件:

jar cfe bybys.jar bardejov.Image bardejov/Image.class bardejov/Board.class bardejov/*jpg

您不需要编写和添加自定义清单。

资源

更新

以下内容在我的机器上有效:

example/Hello.java 创建一个 java 源文件:

package example;
public class Hello {
  public static void main(String[] args) {
    System.out.println("Hello world!");
  }
}

使用命令

javac example/Hello.java

jar 使用命令

jar cfe example.jar example.Hello example/*.class

编译使用命令执行

java -jar example.jar

输出是

Hello world!

Update2

现在看起来比如配置问题。代码和 jar 显然是正确的。

对于快速修复/解决方法:编写一个简短的批处理或 shell 脚本文件,只需执行 java -jar ... 命令,而不是直接启动 jar。

As from Java 6 you can specify an entry point with the jar command. The following command should create an executable jar file for your application:

jar cfe bybys.jar bardejov.Image bardejov/Image.class bardejov/Board.class bardejov/*jpg

You don't need to write and add a custom manifest.

Resource

Update

The following works on my machine:

create a java source file at example/Hello.java:

package example;
public class Hello {
  public static void main(String[] args) {
    System.out.println("Hello world!");
  }
}

compile with command

javac example/Hello.java

jar with command

jar cfe example.jar example.Hello example/*.class

execute with command

java -jar example.jar

The output is

Hello world!

Update2

Now it looks like a configuration issue. The code and the jar are obviously correct.

For a quick fix/workaroud: Instead starting the jar directly, write a short batch or shell script file that simply executes the java -jar ... command.

極樂鬼 2025-01-11 03:28:40

打开 cmd 提示符并键入,

set JAVA_HOME=c:\PATH\TO\JAVA_DIRECTORY
set CLASSPATH=.;%JAVA_HOME%\bin;%JAVA_HOME%\lib

确保将这些变量也包含在您的 PATH 环境变量中。

Win7中的环境变量可以通过控制面板->系统->高级系统设置->高级选项卡->环境变量。

open cmd prompt and type

set JAVA_HOME=c:\PATH\TO\JAVA_DIRECTORY
set CLASSPATH=.;%JAVA_HOME%\bin;%JAVA_HOME%\lib

make sure to include these variables in your PATH environment variable, as well.

You can get to environment variables in Win7 by going to Control Panel -> System -> Advanced System Settings -> Advanced tab -> Environment Variables.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文