Reputation: 609
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.
Upvotes: 0
Views: 41
Reputation: 5291
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 *
Upvotes: 1