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
Christophe Herreman is a software developer living in Belgium. He's working on high-end Flex and AIR solutions at 
February 24th, 2006 at 2:31 am
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.
March 24th, 2006 at 3:49 pm
I can only aggre with Daid Tarico. Thanks for descriping and reporting
April 10th, 2006 at 8:19 am
Thanks Christophe,
It was so simple, but didn’t got noticed
May 12th, 2006 at 3:49 pm
Just want to say Thanx for such an easy solution!!!!
May 25th, 2006 at 1:42 am
I get the same problem, but your solution did not work for me. The ANT HOME is set correctly. Any other ideas???????
TIA
Brian
May 25th, 2006 at 2:06 am
I had to get ANT out of my PATH before I ran eclipse to make this work.
June 6th, 2006 at 12:15 pm
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~
July 11th, 2006 at 12:06 am
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.
August 11th, 2006 at 2:54 pm
txxx man
u rock
September 6th, 2006 at 7:51 am
Push the “Restore Defaults” Button in the Ant/Runtime Settings and then
“Apply”. And everything will work fine…
Jesus is Lord!
October 18th, 2006 at 7:53 pm
this may sound stupid but.
can be done through Window->Preferences->Ant->Runtime
where is windows lol
January 3rd, 2007 at 12:26 pm
I have tried all the solutions above but it did not work
what to do???????????
January 3rd, 2007 at 2:08 pm
I still get the error what to do?
January 10th, 2007 at 12:11 am
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.
January 16th, 2007 at 11:31 am
another solution :
maybe you had added some external jar to your project, remove them and refresh,then try again…
February 1st, 2007 at 1:08 am
THANK YOU!!
February 15th, 2007 at 12:34 pm
Thanks alot! Simple solutions like this is exactly what I want
February 16th, 2007 at 12:51 am
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
March 13th, 2007 at 10:20 am
Thanks Christophe a nice simple quick solution.
March 21st, 2007 at 10:39 am
Thanks a lot, Christophe. I got the same problem.
April 15th, 2007 at 7:11 am
Interesting comments..
June 19th, 2007 at 3:55 pm
Thanks for the tip, saved me hours and hours of fiddling.
August 24th, 2007 at 7:29 pm
Awesome! That worked perfectly!
August 30th, 2007 at 11:48 pm
Thanks, this worked for me.
September 10th, 2007 at 2:44 am
!!! sweet !!! worked for me too just like that !
September 12th, 2007 at 6:41 pm
thx man
rock!!!!!!!
September 26th, 2007 at 11:35 am
Hey very nice, easy & simple solution.
Thanx Chris
October 3rd, 2007 at 3:24 pm
I use Resion in my project.
The similar problem occured and the solutions above don’t work.
SOS!!!
October 15th, 2007 at 12:01 pm
Same issue but resolved after changing the ant home, I had to “validate” it by expanding ant home entries…
November 30th, 2007 at 8:15 am
when i double click on myApp.jar
error display could not find the main class program will exit
plz give me solution
December 17th, 2007 at 8:08 am
good!
December 21st, 2007 at 1:31 pm
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!!!
January 2nd, 2008 at 9:58 am
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..
January 7th, 2008 at 9:50 pm
I’m very new to Eclipse. How can I find the added external jars? And How can I remove and refresh? Please help! Thanks.
January 7th, 2008 at 10:20 pm
I got it works by copy and past the Test.class into the {project-name}/classes directory. What’s wrong with my set up?
January 7th, 2008 at 11:35 pm
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!
January 15th, 2008 at 1:10 pm
I had the problem for some time. Now it’s been solved. Thanks a lot!
February 11th, 2008 at 4:18 pm
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
February 15th, 2008 at 4:55 pm
Thank you very much! Worked perfectly!
April 10th, 2008 at 1:04 am
Thanks, its a great help
May 12th, 2008 at 1:55 pm
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.
July 20th, 2008 at 11:43 am
Hello. I think you are eactly thinking like Sukrat. I really loved the post.
July 21st, 2008 at 8:58 am
Thanks a LOT. This made my day.
July 31st, 2008 at 10:39 am
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.
August 11th, 2008 at 10:48 pm
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.
November 12th, 2008 at 12:17 pm
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
January 18th, 2009 at 6:23 am
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
—
February 1st, 2009 at 12:59 pm
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!!!
February 26th, 2009 at 1:41 pm
Thanks !!!!
Helps me fix the error.
Many Thanks.
– Nilesh
April 2nd, 2009 at 11:43 pm
God bless you man! I was dealing with the same error and thanks to your post I was able to resolve it.
April 9th, 2009 at 4:06 pm
Thanks loads! That did the trick and save me a lot of time.
April 24th, 2009 at 11:12 am
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..
May 9th, 2009 at 7:34 pm
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).
June 5th, 2009 at 2:03 pm
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….
June 28th, 2009 at 5:03 pm
Nice help!!! thanks a lot Christophe!! Regards from Argentina.
July 3rd, 2009 at 7:07 am
“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.
August 11th, 2009 at 10:38 pm
gracias!!!!
September 7th, 2009 at 11:19 am
Thanks Christophe,
it’s solved the problem!
November 22nd, 2009 at 2:31 am
Thanks a lot… its really quick fix the issue.
December 30th, 2009 at 7:42 pm
I tried several tricks posted elsewhere, none worked. Your solution was an easy fix.
Thanks Christophie!!
March 10th, 2010 at 10:55 am
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.
April 6th, 2010 at 2:27 pm
Hi .. I had a similar issue .. this solution helped.. Thanks
April 6th, 2010 at 5:21 pm
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??
May 5th, 2010 at 2:27 pm
Thanks dude…
nice solution, i am worrying about this problem since last two days.
June 4th, 2010 at 4:37 am
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
July 6th, 2010 at 3:52 pm
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”
July 6th, 2010 at 3:55 pm
above error
I am getting at run time and showing popup also sayin
Could not find the main class. Program will exit.
September 22nd, 2010 at 8:09 am
Thanks a lot.
December 14th, 2010 at 9:50 pm
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!
February 10th, 2011 at 5:46 am
Thanks a lot for the simple solution!!!!!!
February 18th, 2011 at 12:10 am
Thanks for quick small tip.
March 20th, 2011 at 7:47 pm
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.
April 18th, 2011 at 8:01 am
@ rooh47
that really worked changing Compiliance level from 6 to 5 as i was using lower version of jdk
thankx dud
June 18th, 2011 at 1:06 am
Thanks guys..I did have an external jar which was deleted and had to be also removed from Eclipse run configurations.
July 20th, 2011 at 11:22 am
thanks…….it was just little problem but very confusing.
August 29th, 2011 at 2:40 pm
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.
October 17th, 2011 at 12:57 pm
Thanks Chrisfor posting.. Also i removed .rsa and .sf file from META-INF which was giving exception.
November 30th, 2011 at 11:13 am
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.