“Could not find the main class. Program will exit.”

Ant, eclipse Add comments

I just installed the latest available Eclipse version (3.2 milestone 5) and couldn’t run my ANT builds anymore. The error I got in the alert box was “Could not find the main class. Program will exit”.

The problem was that the ANT_HOME variable was still pointing to the previous Eclipse folder and the solution was simply to change the path. This can be done through Window->Preferences->Ant->Runtime. Once there, click the “Ant home…” button in the “Classpath” tab and browse to the ANT plugin folder in your Eclipse installation. Now hit the OK button and try to run the build file again. Everything should work again.


Add to Bloglines - Digg This! - del.icio.us - Stumble It! - Twit This! - Technorati links - Share on Facebook - Feedburner
 

78 Responses to ““Could not find the main class. Program will exit.””

  1. David Tarico Says:

    Thanks tons! I was having the same problem and even though it was trivial to fix, the hard part was figuring out what the problem was and where to go to fix it. I’m always thankful when altruistic people such as yourself post solutions to their problems.

  2. joc Says:

    I can only aggre with Daid Tarico. Thanks for descriping and reporting

  3. Rahul Says:

    Thanks Christophe,

    It was so simple, but didn’t got noticed

  4. Aigloss Says:

    Just want to say Thanx for such an easy solution!!!! :)

  5. Brian Says:

    I get the same problem, but your solution did not work for me. The ANT HOME is set correctly. Any other ideas???????

    TIA

    Brian

  6. Brian Says:

    I had to get ANT out of my PATH before I ran eclipse to make this work.

  7. De Wet Says:

    i had the same problem but it was just that one second it worked and the next it didnt. Well not exactly, I added the sun fscontext.jar and providerutil.jar files to my project and then eclipse wouldnt run apps any more :(

    At least the info here seems to help a bit

    ty
    D~

  8. swaroop Says:

    The reson for that error was check for the vm args I the link of javadoc in place of vm args then I got such an error check for that and see.

  9. Ams Says:

    txxx man
    u rock

  10. systolix Says:

    Push the “Restore Defaults” Button in the Ant/Runtime Settings and then
    “Apply”. And everything will work fine…

    Jesus is Lord!

  11. Bob Says:

    this may sound stupid but.

    can be done through Window->Preferences->Ant->Runtime

    where is windows lol

  12. Bilkis Says:

    I have tried all the solutions above but it did not work
    what to do???????????

  13. Bilkis Says:

    I still get the error what to do?

  14. David Says:

    I have a similar problem. When running a simple java class just containing a main method that does System.out.println(“Test”) from inside eclipse I get the message “Could not find the main class. Program will exit”. On the other hand, when I execute the generated class file from cmd shell with “java ” command the operation is successful and the program is launched successfully.

  15. Afei Says:

    another solution :
    maybe you had added some external jar to your project, remove them and refresh,then try again…

  16. dk Says:

    THANK YOU!!

  17. Emil Stenström Says:

    Thanks alot! Simple solutions like this is exactly what I want :)

  18. Josh Says:

    I have the same problen but when i’m installing macromedia coldfusion and i don’t know what else to do… maybe you can help me with this…

    thanx

  19. Paul Schmidt Says:

    Thanks Christophe a nice simple quick solution.

  20. José A. Barba Says:

    Thanks a lot, Christophe. I got the same problem.

  21. imparare Says:

    Interesting comments.. :D

  22. Dante Says:

    Thanks for the tip, saved me hours and hours of fiddling. :)

  23. Stephen NG Says:

    Awesome! That worked perfectly!

  24. Matt Says:

    Thanks, this worked for me.

  25. Jerry Says:

    !!! sweet !!! worked for me too just like that !

  26. SneG Says:

    thx man
    rock!!!!!!!

  27. UshaKiron Says:

    Hey very nice, easy & simple solution.

    Thanx Chris :)

  28. flory Says:

    I use Resion in my project.
    The similar problem occured and the solutions above don’t work.
    SOS!!!

  29. guillaume Says:

    Same issue but resolved after changing the ant home, I had to “validate” it by expanding ant home entries…

  30. chirag Says:

    when i double click on myApp.jar
    error display could not find the main class program will exit
    plz give me solution

  31. wow gold Says:

    good!

  32. Rocky Says:

    Christophe, Thanks a ton for this nice simple and quick solution. I was able to resolve my which I was not able to figure out.

    You rock buddy!!!

  33. confusion:( Says:

    This may be very silly but still, here i am running my project from the shell when i run the ant command target folder is created with .jar files in it. Now when i try to run the .jar file with javaw it gives the above error that “could not find…”. can anyone solve this problem in the meta-inf folder created there is not .mf (manifest file) created wen the project is built. please reply..

  34. Agelina Says:

    I’m very new to Eclipse. How can I find the added external jars? And How can I remove and refresh? Please help! Thanks.

  35. Agelina Says:

    I got it works by copy and past the Test.class into the {project-name}/classes directory. What’s wrong with my set up?

  36. Agelina Says:

    I resolved the problem now. Thanks!

    The problem is that my simple Java class did not compiled inside Eclipse (when I hit Build Project) due to another classes in the same package got errors and I didn’t see the error message until now. After fix the error messages and build again and make sure that the HelloWorld.call is there in my {project-name}/classes directory, it works!

  37. Joe Says:

    I had the problem for some time. Now it’s been solved. Thanks a lot!

  38. rooh47 Says:

    Dear All,
    i am just posting this may it can help someone,i had same probem when i run project on elipse,actually on elipse we had to manage lot of configurations, some time when you people are adding some lib to project then you have to check its setting if you got error.

    Solution to Error in my Case,
    Default Setting for Compiliance level is 6.0 in elipse and if you have any lower version of jdk then 6.0 then you have to change that according to your Compiler version,then you will not see that error again,
    you can change level from:::Windows->Preferences->Compiler->Compler Compiliance level
    thanks to all

  39. DarkMan Says:

    Thank you very much! Worked perfectly!

  40. gala Says:

    Thanks, its a great help

  41. Chris Says:

    Hi,

    Thanks for this fix. As a side note, you will also get this error if you make a mistake when inputting VM arguments. For instance, I forgot the ‘-’ in front of one of my VM args and got the same error, so if the above fix doesn’t work then check your VM args.

  42. professional Says:

    Hello. I think you are eactly thinking like Sukrat. I really loved the post.

  43. daMax Says:

    Thanks a LOT. This made my day.

  44. Vlad Says:

    I had the same problem after I had migrated my workspace from eclipse 3.3 to eclipse 3.4.
    I tried all solutions presented here but none worked. The only one what helped was to create a new workspace and to copy all projects into it.

  45. Paul Says:

    I had this problem going from Eclipse 3.3 to 3.4.
    The original solution (Ant Home) fixed my problem.
    I was about to abandon 3.4 and go back to 3.3.
    Something odd is happening because my Ant Home Entry was
    already pointed at the Ant plug-ins directory. I used the
    Ant Home button to point it to that same directory and
    now I can run my Ant builds. Strange.

  46. Abdul Areef Says:

    Hi Friend,

    in my application, i have layers like EJB -> Struts -> JSP, but i am trying to change the layers like EJB -> Struts -> Flex, with WebORB. i dont like to change the Layers. i dont know how i am going to achieve the Goal. for that i need your suggestion to reach the target, i am expecting your support for this,

    thanks
    areef

  47. Bharat Anand Says:

    Solution posted by rooh47 (see below) did the magic for me -


    Solution to Error in my Case,
    Default Setting for Compiliance level is 6.0 in elipse and if you have any lower version of jdk then 6.0 then you have to change that according to your Compiler version,then you will not see that error again,
    you can change level from:::Windows->Preferences->Compiler->Compler Compiliance level
    thanks to all

  48. eclipse reinstall Says:

    If you guys installed a newer version of eclipse and deleted the previous version, and you are getting the “… Program Will Exit… ” error, then try deleting or moving your previous Workspace folder to another location. Then open eclipse again. Eclipse will automatically create a new workspace folder for you… and hopefully it’ll work. :) It worked for me. I just deleted my previous owrkspace fold that I used to use before. And opened eclipse again and wallah!!!

  49. Nilesh Says:

    Thanks !!!!

    Helps me fix the error.

    Many Thanks. :)

    – Nilesh

  50. Chus Says:

    God bless you man! I was dealing with the same error and thanks to your post I was able to resolve it.

  51. Marc Says:

    Thanks loads! That did the trick and save me a lot of time.

  52. Udit Says:

    Hi everybody…
    I am actually new to this software developing thing…and I have very recently started with Java..For the first time, today, i tried my codes at Eclipse 3.4..and it was really dissappointing to get the usual error ” COULD NOT FIND THE MAIN CLASS. PROGRAM WILL EXIT “.

    i googled around quite a bit…but all in vain…i also tried with Ant Home thing..but what what actually worked for me was
    “Compiler Comiliance level…to be set to 1.5″ (and not 1.6), since i had jdk 1.5 installed in my system..

    Thanx for the solution everybody.. :) :)

  53. JFreddy Says:

    Another solution: Project->Clean, Clean all projects.

    Sometimes a bad build happens and some of the .class files aren’t built (this is what the error means when it says ‘can’t find in /your/package/structure’). And since Eclipse is generally auto building, it will only rebuilt everything if you do a complete ground up clean (which the above does).

  54. Indu Says:

    Hi,
    I am trying to integrate Jboss-5.0.0GA with eclipse-Ganymede, when i am starting the Jboss in server window in eclispe, it is showing the error “Could not find the main class. Program will exit.”, and the server encounters a problem and stops.
    What should I do for this. Need some help….

  55. Luciano Says:

    Nice help!!! thanks a lot Christophe!! Regards from Argentina.

  56. sheshi85 Says:

    “main class could not be found,program will exit” and “JAVA_HOME not pointing to the Jdk location “.These were the problems i was facing even though jdk location was set.i tried this way and it worked windows->preferences->ant->runtime->globalentries right click add external jars and open the tools .jar from your jdk location.now it should work.

  57. jorge Says:

    gracias!!!!

  58. Pasquale Lanciotto Says:

    Thanks Christophe,

    it’s solved the problem!

  59. Sandeep Says:

    Thanks a lot… its really quick fix the issue.

  60. Aditi Says:

    I tried several tricks posted elsewhere, none worked. Your solution was an easy fix.
    Thanks Christophie!!

  61. Margot Says:

    To the poster who advises re using the ‘Restore Defaults’ option – your blood is worth bottling! Thank you. I had uninstalled EasyEclipse and replaced it with Eclipse. My Ant runtime was still pointing to the obsolete EasyEclipse and attempting to alter this manually did not work. The ‘Restore Defaults’ button fixed it for me!
    Thank you indeed.

  62. Shanthi Says:

    Hi .. I had a similar issue .. this solution helped.. Thanks

  63. mahdie Says:

    ava.lang.UnsupportedClassVersionError: javax/bluetooth/DiscoveryListener (Unsupported major.minor version 50.0)

    this is my problem,i changed the ant home but nothing happened!can u help me plz??

  64. surendra pulukuri Says:

    Thanks dude…
    nice solution, i am worrying about this problem since last two days.
    :-)

  65. Venky Says:

    Hey Guys,

    I was able to create & execute a JAR file.Was fine with a specific program.
    But now,I’m facing a problem in executing a new JAR file with another class.
    When I double click on the JAR file it displays
    “Could not find Main-Class: XXX . Program will exit”. I wonder why did this
    thing happen? Though the class file was present within the JAR file why it
    couldn’t search it.
    Can anyone of you plz answer this question. I’m into an edge of finishing my project for my organization.
    Appreciate your quick response.
    E-Mail Id: andyvaidyanathan@gmail.com

  66. Raj Says:

    I have completed my coding and was working fine but suddenly i has start giving below error:

    can some 1 help me out its very urgent.

    java.lang.UnsupportedClassVersionError: org/apache/poi/hslf/model/Shape (Unsupported major.minor version 49.0)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    Exception in thread “main”

  67. Raj Says:

    above error
    I am getting at run time and showing popup also sayin

    Could not find the main class. Program will exit.

  68. VidyaSagar Says:

    Thanks a lot.

  69. Sashi Says:

    Hey, thanks a ton. All of a sudden I started getting this problem when I change eclipse version and had plugins pointing to older version. For an hour did not understand why I’m getting this problem. Browsed impatiently and got a solution.

    Thanks very much, a simple fix always get out of notice. But working perfectly for many for past 4 years.

    Kudos!

  70. lakshmi Says:

    Thanks a lot for the simple solution!!!!!! :)

  71. Prashant Says:

    Thanks for quick small tip.

  72. Peter Says:

    I have a solution for another case, which doesn’t seem to have been written here.
    My cause was that I used package name starting with “java.” for my classes, so Ant was searching for them in a standart library. I changed the package root to “my.” and it solved the problem.

  73. Dharshak Says:

    @ rooh47

    that really worked changing Compiliance level from 6 to 5 as i was using lower version of jdk
    thankx dud

  74. Pateek Says:

    Thanks guys..I did have an external jar which was deleted and had to be also removed from Eclipse run configurations.

  75. ajit Says:

    thanks…….it was just little problem but very confusing.

  76. Elliott Says:

    Also (I’m not sure if anybody said this) if it doesn’t work try moving your eclipse folder to a different directory (folder) that doesn’t have symbols in it like *#&$!^. It worked for me.

  77. viraj Says:

    Thanks Chrisfor posting.. Also i removed .rsa and .sf file from META-INF which was giving exception.

  78. Syux. Says:

    Thank you so much for posting this. Trivial issue but did not have a clue where to start with. You saved a lot of my time. thanks.

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in