简体   繁体   中英

Main Class Is In JAR, Can't Be Seen By Jar.exe

To put it simply, I have a different error where Eclipse won't allow me to export the recent version of a JAR. So, I'm trying in command prompt instead.

I'm using JDK 1.8.0.

1) First, I extracted all class files from their individual folders. 2) I created a manifest.txt which contains the following ( including a carriage return at the end as described in the oracle tutorial )

Main-Class: Start

3) I'm creating the runnable jar with the following command, being verbose as possible to ensure correct versioning:

C:\correctDirectory\"C:\Program Files\Java\jdk1.8.0\bin\jar.exe" cvfm ERSR.jar manifest.txt *.class

4) That runs fine. I then inspect the JAR to ensure it containts the Start.class file which contains the main method:

C:\correctDirectory\"C:\Program Files\Java\jdk1.8.0\bin\jar.exe" tf ERSR.jar

The output of that is (reduced to useful info):

META-INF/
META-INF/MANIFEST.MF
Start.class

5) Then I run the JAR with the following command:

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

To which I get the error:

Error: Could not find or load main class Start.

Thanks in advance kind folks.

Does your Start class contain any static field that is initialized with a contents of a resource (a .properties file, or alike)?

If that is the case, then it's likely the problem. The command you use in step 3) only packages the .class files into the JAR, but ignores the rest:

...\\jar.exe cvfm ERSR.jar manifest.txt *.class

Modify it to include everything:

...\\jar.exe cvfm ERSR.jar manifest.txt *

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM