Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't run JAR file: "Could not find the main class"

Status
Not open for further replies.

RebLazer

Programmer
Jun 7, 2002
438
US
When attempting to execute a JAR file - either from the command line or from Windows Explorer, the JVM throws up a dialog box stating, "Could not find the main class. Program will exit!" I looked around on the Web and see that a suspect is the JAR file itself. But that can't be the problem as my coworkers on the same network are able to successfully run that very same JAR file, simply by double clicking on it.

I have JBuilder 6.0 Professional on my computer and am able to run Java applications without any problems.

Any ideas what could be different with my computer?

Thanks,
RebLazer :)
 
Well, probably one of two :

1. Your machine is not configured to open (execute) jar files.

2. It might open it, but the invoking command line be misconfigured (class not found).

 
Danny,

Perhaps you or someone else out there could elaborate a bit on what the solution might be... :)

Thanks.
 
Well the jar file apparently has no main class.
Try opening the jar (with winzip) and taking a look inside.

Whats the jar meant to do ??
 
Your JAR must contain a manifest file which must specify a valid Main-Class. A JAR structure resembles:

Code:
META-INF
  \--> MANIFEST.MF  <--- manifest
com
  \--> mycompany
         \--> myapp
                \--> MyMain.class
                \--> MyOther.class

The manifest should contain a line like:

Main-Class: com.mycompany.myapp.MyMain

HTH, Cheers Neil :)



 
Also perhaps the Main-Class points to a class EXTERNAL to the jar, so other people might be able to run the jar if they have this Main-Class somewhere in their CLASSPATH? I'm not even sure this is a legal setting for Main-Class, but it may explain why others could be able to get the jar working?

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top