无法使用Jar文件查找或加载主类 [英] Could not find or load main class with a Jar File

查看:96
本文介绍了无法使用Jar文件查找或加载主类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用

@echo off
java -jar Test.jar
pause

使用

Manifest-Version: 1.0
Main-Class: classes.TestClass


b $ b

在Jar目录中,我可以清楚地看到一个classes \TestClass文件,当我提取它。

In the Jar directory, I can clearly see a classes\TestClass file when I extract it.

编辑: .TestClass 有一个 public static void main(String [] args)

包装减速在 classes.TestClass 包类;

但我仍然收到错误讯息

Could not find or load main class classes.TestClass

我已经找到了有这个问题,没有一个似乎有帮助。

I've been through everything I've been able to find with this problem, and none of it seems to help.

我已经尝试编辑类路径,重做清单,安装新的JRE。

I've tried editing the classpath, redoing the manifest, installing the new JRE.

我还应该做什么?

推荐答案

我的工作方式如下:

TestClass.Java

package classes;

public class TestClass {

    public static void main(String[] args) {
        System.out.println("Test");
    }

}

使用 javac 在命令行中生成 TestClass.class 。将 TestClass.class 放在文件夹 classes / 中。

Use javac on the command line to produce TestClass.class. Put TestClass.class in a folder classes/.

MANIFEST.MF

Manifest-Version: 1.0
Main-Class: classes.TestClass

然后运行

jar cfM MANIFEST.MF test.jar classes/

/ p>

Then run it as

java -jar test.jar

这篇关于无法使用Jar文件查找或加载主类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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