You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

主类存在于JAR中却无法识别:JDK1.8下JAR运行报错求助

Fixing "Could not find or load main class Start" When Running Your JAR

Let me walk you through the most likely fixes for this frustrating error—this is a super common issue with JAR packaging and manifest files, so we’ll get it sorted out!

1. Double-check if Start is in the default package

If your Start class is part of a package (e.g., com.myapp.Start), your Main-Class entry in the manifest must include the full package path, not just Start. To confirm:

  • Run this command in your C:\correctDirectory folder:
    "C:\Program Files\Java\jdk1.8.0\bin\javap.exe" Start
    
  • Look at the output: if it says public class Start, you’re in the default package (good). If it shows public class com.myapp.Start, update your manifest to Main-Class: com.myapp.Start.

2. Verify your manifest file’s format is perfect

Manifest files are picky about formatting—even tiny mistakes break things:

  • Make sure there’s exactly one space after the colon in Main-Class: Start (no missing space, no extra spaces).
  • Ensure the file ends with a newline character (you mentioned this, but double-check—sometimes text editors hide this).
  • Extract the actual manifest from your JAR to confirm:
    "C:\Program Files\Java\jdk1.8.0\bin\jar.exe" xf ERSR.jar META-INF/MANIFEST.MF
    
    Open MANIFEST.MF in a plain text editor (Notepad works) to check for hidden characters, extra lines, or typos.

3. Confirm Start.class is in the correct location in the JAR

When you run jar tf ERSR.jar, look closely at the output:

  • Start.class should be listed directly at the root of the JAR (e.g., just Start.class, not some/folder/Start.class).
  • If you extracted class files from subfolders, you might have accidentally included the folder structure in the JAR. For example, if Start.class was in bin/Start.class, make sure you’re running the jar command from the bin folder, or copy the class files directly to C:\correctDirectory before packaging.

4. Test running the class directly (outside the JAR)

To rule out classpath issues, run the Start class directly:

cd C:\correctDirectory
"C:\Program Files\Java\jdk1.8.0\bin\java.exe" Start
  • If this works, the problem is definitely with your JAR packaging or manifest.
  • If this also fails, you might be missing dependencies, or Start.class isn’t actually in your current directory.

5. Simplify your java command

Your current run command has nested quotes which might cause unexpected behavior. Try simplifying it:

cd C:\correctDirectory
"C:\Program Files\Java\jdk1.8.0\bin\java.exe" -jar ERSR.jar

Changing directories first avoids any path-related quirks with the JAR file location.

内容的提问来源于stack exchange,提问作者Ken Reid

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:58:10