主类存在于JAR中却无法识别:JDK1.8下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:\correctDirectoryfolder:"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 showspublic class com.myapp.Start, update your manifest toMain-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:
Open"C:\Program Files\Java\jdk1.8.0\bin\jar.exe" xf ERSR.jar META-INF/MANIFEST.MFMANIFEST.MFin 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.classshould be listed directly at the root of the JAR (e.g., justStart.class, notsome/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.classwas inbin/Start.class, make sure you’re running thejarcommand from thebinfolder, or copy the class files directly toC:\correctDirectorybefore 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.classisn’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

