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:
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.
- 04-02-2009, 09:27 AM #2
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 #3Senior Member
- Join Date
- Dec 2008
- Hong Kong
- Rep Power
javax.mail API is not part of core java API
-cp the mail.jar in netbeans
Last 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?
- 04-02-2009, 09:35 AM #5
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?
- 04-02-2009, 09:53 AM #7
This is the command I used to compile the program via the command line:
javac -classpath "/home/bob/.java/MyJars/*" SendMail.java
- 04-02-2009, 10:50 AM #8
- 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...
- 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
I typed this in (Note: this command will only work on linux!):
Thank you all for your help!
Last edited by bobleny; 04-03-2009 at 06:12 AM.
- 04-03-2009, 04:10 AM #12
- 04-03-2009, 04:35 AM #13
In the teminal.
- 04-03-2009, 04:39 AM #14
- 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.
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.
- 04-03-2009, 08:05 AM #16Member
- Join Date
- Apr 2009
- Rep Power
give correct path name
- 04-03-2009, 09:41 AM #17
- 04-03-2009, 09:41 AM #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!
- 04-06-2009, 03:35 AM #20
- By silvia in forum New To JavaReplies: 2Last Post: 09-22-2011, 09:48 PM
- By ziisrick in forum New To JavaReplies: 6Last Post: 05-18-2010, 05:11 PM
- By aryubi in forum New To JavaReplies: 39Last Post: 02-19-2010, 10:02 AM
- By Syranno in forum New To JavaReplies: 1Last Post: 07-25-2008, 04:07 PM
- By banduskank in forum Advanced JavaReplies: 2Last Post: 06-24-2008, 08:05 AM