Results 1 to 20 of 22
- 04-02-2009, 10: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 11:04 PM.
- 04-02-2009, 10: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, 10: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 10:34 AM.
- 04-02-2009, 10: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, 10: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, 10: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, 10: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, 11:50 AM #8
- 04-02-2009, 10: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, 10: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, 11: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 07:12 AM.
- 04-03-2009, 05:10 AM #12
- 04-03-2009, 05:35 AM #13
In the teminal.
- 04-03-2009, 05:39 AM #14
- 04-03-2009, 08: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 10:41 PM.
- 04-03-2009, 09:05 AM #16Member
- Join Date
- Apr 2009
- Rep Power
give correct path name
- 04-03-2009, 10:41 AM #17
- 04-03-2009, 10:41 AM #18
- 04-03-2009, 10: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, 04:35 AM #20
- By silvia in forum New To JavaReplies: 2Last Post: 09-22-2011, 10:48 PM
- By ziisrick in forum New To JavaReplies: 6Last Post: 05-18-2010, 06:11 PM
- By aryubi in forum New To JavaReplies: 39Last Post: 02-19-2010, 11:02 AM
- By Syranno in forum New To JavaReplies: 1Last Post: 07-25-2008, 05:07 PM
- By banduskank in forum Advanced JavaReplies: 2Last Post: 06-24-2008, 09:05 AM