Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is wrong with my ant configuration?

Tags:

ant

fedora

I installed Ant on a Fedora 5 machine using yum, but Ant does not launch. I get this error message:

[bash]# ant Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/Launcher Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.launch.Launcher     at java.net.URLClassLoader$1.run(URLClassLoader.java:202)     at java.security.AccessController.doPrivileged(Native Method)     at java.net.URLClassLoader.findClass(URLClassLoader.java:190)     at java.lang.ClassLoader.loadClass(ClassLoader.java:307)     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)     at java.lang.ClassLoader.loadClass(ClassLoader.java:248) Could not find the main class: org.apache.tools.ant.launch.Launcher.  Program will exit. 

I have set the following environment variables:

JAVA_HOME = /usr/java/latest ANT_HOME = /usr/bin 

Ant is installed at /usr/bin/ant.

I have also come across this post, and it seems that the JAVAVER_LIBDIR variable does not point to something that exists. I set a symbolic link, like the post suggests cleared the issue up for the author, but it did not fix things for me.

[bash]# sudo ln -s /usr/share/java /usr/share/java-1.6.0 

Edit: I have also set a symbolic link that addressed a similar problem with the JAVAVER_JNIDIR variable:

[bash]# sudo ln -s /usr/lib/java /usr/lib/java-1.6.0 

I now get a different error message:

[bash]# ant --execdebug /usr/bin/build-classpath: error: Could not find jaxp_parser_impl Java extension for this JVM /usr/bin/build-classpath: error: Could not find xml-commons-apis Java extension for this JVM /usr/bin/build-classpath: error: Some specified jars were not found exec "/usr/java/latest/bin/java" -classpath "/usr/share/java-1.6.0/ant.jar:/usr/share/java-1.6.0/ant-launcher.jar:/usr/java/latest/lib/tools.jar" -Dant.home="/usr" -Dant.library.dir="/usr/lib" org.apache.tools.ant.launch.Launcher -cp "" Buildfile: build.xml does not exist! Build failed 

Off to Google these error messages...

like image 874
Scottie T Avatar asked Feb 25 '10 17:02

Scottie T


People also ask

What is Ant configuration?

Ant uses an xml file for its configuration. The default file name is build. xml . Ant builds are based on three blocks: tasks, targets and extension points. A task is a unit of work which should be performed and constitutes of small atomic steps, for example compile source code or create Javadoc.

How do you debug an Ant?

Open the Ant view (Window -> Show view -> Ant). If the build file isn't in the view then you can simply add it. Once added right click on the ant target you want to run and select Debug as -> Ant build. The Debug perspective should open up and the process should stop at your breakpoint where you can step through it.

What version of Java does Ant use?

You will need Java installed on your system, version 1.8 or later required. The later the version of Java, the more Ant tasks you get. The git branch 1.9. x is used for long term support of Ant 1.9.


1 Answers

I've just met similar issue on Fedora 18.

To make long story short, run:

sudo mkdir /usr/lib/java-1.7.0 /usr/share/java-1.7.0 

Apparently, this problem is specific to java-1.7.0-openjdk because similar empty directories for all other JDK versions existed.


DETAILS

There was single-line error after running ant:

Error: Could not find or load main class org.apache.tools.ant.launch.Launcher 

The problem was somewhere in /usr/share/java-utils/java-functions script which tried to set JAVAVER_JNIDIR/JAVAVER_LIBDIR variables to refer to the directories above. Due to inappropriate error message redirection to stdout, some variables got assignments like:

LOCALCLASSPATH='/usr/bin/build-classpath: error: JAVAVER_JNIDIR /usr/lib/java-1.7.0 does not exist or is not a directory' 

Creating the directories according to the convention set by all other java versions is the cleanest solution.

like image 80
uvsmtid Avatar answered Sep 22 '22 13:09

uvsmtid