We help IT Professionals succeed at work.
Get Started

"Could not find the main class" error

jjharr
jjharr asked
on
600 Views
Last Modified: 2013-11-23
My program compiles fine, but when I attempt to launch a java program on Linux using the "java" command, I get a NoClassDefFoundError for a class that is definitely in the classpath and another error that says it could not find the main class. I have ruled out most of the basic problems for this error.

My program is just 40 lines of code and sends a basic email. It links to one jar - the mail.jar available from Oracle/Sun. The command I'm using is :

java MailTest -classpath ./mail.jar

I have unset the $CLASSPATH variable to prevent conflicts. $JAVA_HOME is correctly set and I have tried running the java executable with the full java path with the same result. The directory is readable and writable by the user I'm logged in as. The case in the command matches the case of the MailTest.class file.

The program was compiled with 'javac MailTest.java -classpath ./mail.jar' and successfully generated a MailTest.class file. The NoClassDefFoundError I'm getting is for the javax/mail/Address class which is definitely in the mail.jar file which is explicitly listed in my classpath.

I'm completely stumped. Suggestions?

Comment
Watch Question
Awarded 2011
Awarded 2011
Commented:
This problem has been solved!
Unlock 1 Answer and 19 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE