"Could not load or find main class"日食错误



我是Java编程新手。我有这样一个类,它应该运行一个位于本地磁盘文件夹中的。bat文件:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Execute {
    public static void main(String args[]) 
    {
        String stream = null;
        try {
            Process p = Runtime.getRuntime().exec(
                    "C:\WINDOWS\system32\cmd.exe /c start C:\Identify\dll\StartSample.bat");
            BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
            BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
            // read the output from the command
            System.out.println("Here is the standard output of the command:");
            while ((stream = stdInput.readLine()) != null) 
            {
                System.out.println(stream);
            }
            // read any errors from the attempted command
            System.out.println("Here is the standard error of the command (if any):");
            while ((stream = stdError.readLine()) != null) 
            {
                System.out.println(stream);
            }
            System.out.println("ended!!");
            System.exit(0);
        }
        catch (IOException e) 
        {
            System.out.println("exception happened: ");
            System.err.println(e.getMessage());
            System.exit(-1);
        }
    }
}

无论何时运行.bat文件,它都能正常工作。然而,当我运行我所做的类时,命令提示符显示"C:palmuswebservice>java Error: Could not find or load main class"

我不知道哪里不对。有人能帮我解决这个问题吗?

您必须在JAR文件中添加一个Manifest文件。Manifest文件包含一个名为Main-Class的密钥,它应该是主类

的全名。

清单文件位于(在JAR文件中)META-INFMANIFEST.MF

清单文件的示例如下:
Manifest-Version: 1.0 Main-Class: full.class_.name.MainClass

(在Eclipse中有一个导出可运行JAR文件的选项,它可以很容易地创建这个文件)

相关内容

最新更新