polmarex
polmarex

Reputation: 1383

"Could not find the main class" error

I have a .jar generated by Eclipse, which I cannot run on other computer (with Windows XP). The "Could not find the main class. Program will exit" message appears. That computer runs fine another .jar generated by Netbeans, so it is not a problem with JRE, I guess. I updated JRE but it changed nothing. What is the problem?

UPDATE: I forgot to mention, that I made a runnable jar file. On two another computers it works fine (win 7 and XP), but on that specific one not.

UPDATE 2: It's a Swing application, so the JAR is run by double-clicking.

Upvotes: 0

Views: 2316

Answers (2)

Check the contents of the manifest. The Main-Class: foo.Bar line must correspond to an /foo/Bar.class entry in the jar file, and foo.Bar.java must contain an appropriate main-method. Also all jars reference in the Class-Path: line must be copied too.

Use "jar tvf my.jar" to see the layout.

Upvotes: 1

Bohemian
Bohemian

Reputation: 425033

You must put the jar in the classpath, like this:

java -classpath "C:\somepath\myapp.jar" mypackage.MyClass

Upvotes: 0

Related Questions