tags:

views:

266

answers:

3

Hi, I'm using the JDK 3.1. I am using XML Publisher. I'm getting this error:

Could not find the main class. Program will exit.

After I click on "OK", I get

Java execution failed. Please check the Java Option in the option dialog
+1  A: 

Sounds like you're trying to execute .jar file and there's no Main-Class entry in the manifest file. Other than that obvious point, your question does not give much information for assistance.

Daniil
A: 

Your question is tricky to understand, but I'm guessing that you haven't actually compiled your Java code, or your compiled code isn't on the classpath.

When I try and execute a non-existent class (this would work if there was a MyClass.class on the classpath with a main() method):

paul@paul-laptop:~$ java MyClass
Exception in thread "main" java.lang.NoClassDefFoundError: MyClass
Caused by: java.lang.ClassNotFoundException: MyClass
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: MyClass.  Program will exit.

Is that what you're seeing? If so:

  • compile your class with javac if you haven't done so
  • check that your classpath includes the location of the class

(You can specify the classpath explicitly when you execute the java program using -classpath, check the documentation for details.)

Brabster
A: 

I include this answer as someone who has made an error someone consuming java rather than programming in it would make:

On the command line when executing a JAR file, be sure your line reads
java -jar whatever.jar

instead of

java whatever.jar

Without the -jar you sometimes get the "Could not find the main class" error.

Plynx