Results 1 to 20 of 22
- 04-02-2009, 09:21 AM #1
[SOLVED] Could not find the main class: error...
OK, one more thing... I hope.
Sometimes I just feel helpless...
I compiled my little program with netbeans. I than ran it with netbeans and everything is perfect. However, when I want to run it from the command prompt, it spazes out on me! So, I tried compiling it from the command line, but I get the same error when I attempt to run it...
This is what I get:
This error makes no sense to me. I don't know where even to begin on decoding this error...Java Code:bob@GeorgeJr:~/Programming/java/NetBeans/SendMail/build/classes$ java SendMail Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingException Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException 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: SendMail. Program will exit. bob@GeorgeJr:~/Programming/java/NetBeans/SendMail/build/classes$
Once again, I thank you for your help!Last edited by bobleny; 04-02-2009 at 10:04 PM.
-- www.firemelt.net --
Cheer up, the worst has yet to come...
- 04-02-2009, 09:27 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
That's because javax.mail package is not in the same place as your main class is contain. Or not in the class path. I hope you import those packages from the NetBeans.
- 04-02-2009, 09:29 AM #3
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
javax.mail API is not part of core java API
-cp the mail.jar in netbeansLast edited by mtyoung; 04-02-2009 at 09:34 AM.
- 04-02-2009, 09:33 AM #4
I have mail.jar listed as a compile time library, which allows it to compile. I don't understand why it wont run then?
-- www.firemelt.net --
Cheer up, the worst has yet to come...
- 04-02-2009, 09:35 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You are talking in related with NetBeans right?
NetBeans refer the path when you import the package from the project properties. But command prompt doesn't know that.
- 04-02-2009, 09:38 AM #6
Yeah, I understand that netbeans knows where they are, which is why it will run in netbeans.
Theres got to be a way to "package" the class and jar files so that it runs on command line right?-- www.firemelt.net --
Cheer up, the worst has yet to come...
- 04-02-2009, 09:53 AM #7
This is the command I used to compile the program via the command line:
It compiles fine, I set the classpath, I just don't understand why it wont run... :'(Java Code:javac -classpath "/home/bob/.java/MyJars/*" SendMail.java
-- www.firemelt.net --
Cheer up, the worst has yet to come...
- 04-02-2009, 10:50 AM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Try to add those packages in to the classpath and try to run the application.
- 04-02-2009, 09:02 PM #9
Well, could someone explain this classpath thing to me? I obviously just don't understand...
I thought, [-classpath "/home/bob/.java/MyJars/*"] was setting the classpath.
I've read a bunch of different articles that explain what it is, but nothing I've read seems to be able to tell me how to do it in a comprehensive way.
This is so frustrating...-- www.firemelt.net --
Cheer up, the worst has yet to come...
- 04-02-2009, 09:38 PM #10
when you use the -cp or -classpath switch, its not permanent. so "Try to add those packages in to the classpath and try to run the application."
USE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 04-02-2009, 10:04 PM #11
Thank god!
I typed this in (Note: this command will only work on linux!):
Now it works! :DJava Code:export CLASSPATH=$CLASSPATH:/home/bob/.java/MyJars/mail.jar:.
Thank you all for your help!Last edited by bobleny; 04-03-2009 at 06:12 AM.
-- www.firemelt.net --
Cheer up, the worst has yet to come...
- 04-03-2009, 04:10 AM #12
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Where did you type this command?
- 04-03-2009, 04:35 AM #13
- 04-03-2009, 04:39 AM #14
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
So you have to type this command each time on the command interpreter, right?
- 04-03-2009, 07:13 AM #15
Well, kind of. As it turns out, after I reboot my computer I have to type the command in again. However, I only need to type it once per boot.
In my readings, I remember the mentioning of ".bashrc" file in my home directory. I think that if I copy that command into that file, It will always work... We will see what happens.
Edit-
Placing the command in .bashrc, does the trick! After rebooting, the classpath is still there!Last edited by bobleny; 04-03-2009 at 09:41 PM.
-- www.firemelt.net --
Cheer up, the worst has yet to come...
- 04-03-2009, 08:05 AM #16
Member
- Join Date
- Apr 2009
- Posts
- 37
- Rep Power
- 0
give correct path name
- 04-03-2009, 09:41 AM #17
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 04-03-2009, 09:41 AM #18
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 04-03-2009, 09:44 PM #19
Just a quick update...
Placing the classpath command in .bashrc, does allow it to work immediately after a reboot.
I have also finished my program and it does exactly what it is supposed to do!
Thanks again for all your help!-- www.firemelt.net --
Cheer up, the worst has yet to come...
- 04-06-2009, 03:35 AM #20
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Similar Threads
-
Error: Could Not Find Main Class. Program Will Exit
By silvia in forum New To JavaReplies: 2Last Post: 09-22-2011, 09:48 PM -
"Could not find the main class: comparisonDemo.class. Program will exit."
By ziisrick in forum New To JavaReplies: 6Last Post: 05-18-2010, 05:11 PM -
Could not find the main class, program will exit.
By aryubi in forum New To JavaReplies: 39Last Post: 02-19-2010, 10:02 AM -
Could not find main class - JDK 1.6
By Syranno in forum New To JavaReplies: 1Last Post: 07-25-2008, 04:07 PM -
JVM Could not find main class
By banduskank in forum Advanced JavaReplies: 2Last Post: 06-24-2008, 08:05 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks