Scottie T
Scottie T

Reputation: 12195

What is wrong with my ant configuration?

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...

Upvotes: 30

Views: 51875

Answers (12)

Rajitha Sasanulu
Rajitha Sasanulu

Reputation: 1

Run which ant to know if the ant_home set. If not please run below with your corresponding paths to set ant_home:

export ANT_HOME=/ade_autofs/gd29_3rdparty/ANT_1.7.1_GENERIC.rdd/080925/ant 
export PATH=$ANT_HOME/bin:${PATH}

Upvotes: 0

Jlearner
Jlearner

Reputation: 613

In my case 'lib' folder which has all jars including

ant-launcher.jar

was under

/usr/local/Cellar/ant/1.9.6/libexec/ 

I copied lib folder under

/usr/local/Cellar/ant/1.9.6/

because after running 'ant --execdebug' i found ant commands are looking for 'lib' folder under '1.9.6' folder.

after that change ant commands started working fine.

Upvotes: 0

harmic
harmic

Reputation: 30577

I had the same error message today, but triggered by a different cause.

In my case, after I updated to OpenJDK 1.8.0, I could no longer run ant.

The problem lied with the fact that the output of the java -fullversion command had changed slightly, and the /usr/share/java-utils/java-functions no longer correctly understood it.

Upgrading to the latest version of the jpackage-utils RPM solved it for me.

Upvotes: 4

AndyB
AndyB

Reputation: 31

I was having the exact same error message on OS X, but somebody suggested unsetting ANT_HOME and that worked. https://github.com/Homebrew/homebrew/issues/32851

Upvotes: 1

Matt Clark
Matt Clark

Reputation: 28579

In my case, I was setting my ANT_HOME variable, but had /bin/ appended for use in the system path - this home variable should not be the binary directory, use the following for setting an ant hime, and adding the binary directory to the env path.

export ANT_HOME=/opt/apache-ant-1.9.4
export PATH=$ANT_HOME/bin:$PATH

Upvotes: 2

user2232387
user2232387

Reputation: 201

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

I installed sun java 1.7.x by downloading the tar file and placing it in /opt. Because I didn't do a yum install these directories were not created. My JAVA_HOME is set to:

$ echo $JAVA_HOME/
/opt/jdk1.7.0_03/

As someone else said, running the following provided very useful debug:

ant --execdebug

Upvotes: 13

uvsmtid
uvsmtid

Reputation: 4295

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.

Upvotes: 26

Maciej Bielski
Maciej Bielski

Reputation: 129

I had such problem on Fedora 16 but in my case xerces packages and xml-commons-apis was ok. Actually, --execdebug is very helpful and it printed that ant cannot find a directory at /usr/lib/jvm-exports/YOUR_JDK. This was because I switched from openjdk to oracle's jdk and the directory of former version of jdk (/usr/lib/jvm-exports/java-1.6.0-openjdk-1.6.0.0) left there but there was not the one of my current version (/usr/lib/jvm-exports/jdk1.6.0_32). These directories includes only a bunch of soft links that point to particular jre's jars so I've taken following steps:

  1. create a new directory for current version of jdk (jdk1.6.0_32)
  2. copy all links from the openjdk's directory to the new directory
    # cp -av java-1.6.0-openjdk-1.6.0.0.x86_64/* jdk1.6.0_32/
  3. correct all of them so as they are pointing on oracle's jars, example:
    # cd /usr/lib/jvm-exports/jdk1.6.0_32
    # ln -s -f $JAVA_HOME/jre/lib/rt.jar jaas-1.6.0.0.jar

Obviously, $JAVA_HOME is set correctly (on the new jdk version). It solved my problem and can be another cause excepting the causes mentioned above.

Upvotes: 3

david
david

Reputation: 33517

I had a similar problem but the following fixed it for me:

sudo yum install xml-commons-apis

Upvotes: 6

Jason Stirnaman
Jason Stirnaman

Reputation: 11

I had the same problem on Suse, SLES 11. Hidayath's answer https://stackoverflow.com/a/4849302/1211900 solved it. Assuming out-of-the-box package repositories: me@sles:~> sudo zypper install xerces-j2-xml-apis

Upvotes: 1

Hidayath
Hidayath

Reputation: 21

Try installing xerces-j2-xml-apis

Upvotes: 2

Aito
Aito

Reputation: 6872

I think that the ANT_HOME should be set with '/usr/bin/ant'. I have that configuration (CENTOS 5).

My sh script under '/etc/profile.d' has this conf.:

export JAVA_HOME="/usr/local/java";
export ANT_HOME="/usr/local/ant";

I hope it helps you.

Upvotes: 12

Related Questions