Running Ant Build.xml getting: Java Virtual Machine Launcher: Could not find the main class. Program will exit
Asked Answered
R

6

6

I am writing my code in eclipse, the code is running fine but when I try to build it in ant by running build.xml. I am getting

Java Virtual Machine Launcher: Could not find the main class. Program will exit.

Any suggestions?

Rochet answered 2/7, 2013 at 4:22 Comment(5)
are you running as "Java Application" or "Ant Build"?Pushy
I am running Ant Build.Rochet
can you post your build.xmlPushy
I can run this build.xml on another machine but not on my machine. I don't think there's anything wrong with the xml. Which part of xml will you like me to post?Rochet
If you are launching ANT build inside Eclipse, then check the Eclipse settings e.g. Eclipse -> Preferences -> Ant -> Runtime and check apprpriate tools.jar is on classpath of ANT runtime. If not set it. In my eclipse it is under ANT -> Runtime -> Global Entries.Buffer
E
5

You need to verify few things
1) Is the path to java bin directory set properly?? (To check this you need to write command javac in command prompt(cmd) and you will get a list of instructions on cmd console)
2) Open the eclipse and go to Window-> Preferences-> Ant-> Runtime
in the Classpath tab, see Ant Home Entries pointing to the wrong directory (it still points to the last directory, this directory does not exist) you have to do is to change the Ant Home pointing to the correct directory, to point Ant Home button
select Ant Home directory, for example, I use Eclipse 3.3.1, Ant Home is the Eclipse plugin directory org.apache.ant_1. 7.0.v200706080842.

Enucleate answered 2/7, 2013 at 5:18 Comment(0)
E
16

if you are using java 1.6 and upgraded eclipse, it's more likely caused by eclipse the solution is to go to Run as → External tools configuration… → JRE where the default was set to “Separate JDK”: jdk1.6.0_31 and change this to “run in the same JRE as the workspace” (1.7/1.8), and it should works.

Bug fix would be to provide a working default configuration with setup. Configuration should be in a way it does not break if the user adds additional JDKs to Preferences.

for more details you can see Bug 472599

Erland answered 3/10, 2015 at 0:9 Comment(1)
You saved me. Also, I didn't have to go through "External configuration". I went to "Run as → Ant Build... → JRE → Run in the same JRE as the workspace".Zoolatry
E
5

You need to verify few things
1) Is the path to java bin directory set properly?? (To check this you need to write command javac in command prompt(cmd) and you will get a list of instructions on cmd console)
2) Open the eclipse and go to Window-> Preferences-> Ant-> Runtime
in the Classpath tab, see Ant Home Entries pointing to the wrong directory (it still points to the last directory, this directory does not exist) you have to do is to change the Ant Home pointing to the correct directory, to point Ant Home button
select Ant Home directory, for example, I use Eclipse 3.3.1, Ant Home is the Eclipse plugin directory org.apache.ant_1. 7.0.v200706080842.

Enucleate answered 2/7, 2013 at 5:18 Comment(0)
D
3

Right click on the build.xml file and select Run As --> External tool configurations --> Jre --> Select Run in the same JRE as the workspace.

Delozier answered 23/5, 2018 at 3:32 Comment(1)
Thanks, it worked. The project was using Java 6 but the Eclipse's Ant needed Java 8.Kaine
K
1

If you are using Java 1.5 (that is, it is specified in your workspace, project or ant configuration as the JVM to use), it is also caused by a bug/feature in Eclipse: Java 1.5 is no longer supported. You need to upgrade to Java 1.6.

See: Eclipse bugs 421423

Krefetz answered 21/9, 2015 at 12:50 Comment(0)
C
0

The version of ant you're using may not be compatible with the version of java you are using. I have ant 1.9.4 and was trying to run with java 1.4 and got this same error. Running with java 1.7 fixed it for me!

Cochleate answered 20/4, 2015 at 19:56 Comment(0)
N
0

Error I was facing :

"Could not find the main class : 
org.eclipse.ant.internal.launching.remote.internalAntRunner. Program will exit."

To compile my code with JDK 1.8, i have added external ANT to my eclipse, which was working fine. But compiling the code with JDK 1.6 with same ANT version was not working.

Solution : I restored the ANT in to its default value by selecting " Restore Default Entries " ( ANT --> Run as --> External Tools configurations --> classpath" ), after that ANT with JDK 1.6 is working fine.

Above error was happening for me when i added external ANT to my eclipse which was compatible with JDK 1.8 usage. Ant was working with JDK 1.8, the same was not working with 1.6 JDK. Once i restored ANT classpath settings to its default eclipse values which was JDK 1.6 compatable, above error was gone.

Newly answered 29/8, 2022 at 13:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.