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

StackOverflow https://stackoverflow.com/questions/17417346

  •  02-06-2022
  •  | 
  •  

Question

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?

Was it helpful?

Solution 2

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.

OTHER TIPS

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

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

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

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top