Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying web app using Ant results in NoClassDefFoundError

Tags:

java

tomcat

ant

I'm using Ant 1.9.3 and Tomcat version 8.0. I'm using the Ant deploy target to deploy web apps in the Apache Tomcat using the manager credentials. The deploy target fails with the following exception:

java.lang.NoClassDefFoundError:
 org/apache/tomcat/util/codec/binary/Base64
        at org.apache.catalina.ant.AbstractCatalinaTask.execute(AbstractCatalina
Task.java:204)
        at org.apache.catalina.ant.DeployTask.execute(DeployTask.java:196)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:106)
        at org.apache.tools.ant.Task.perform(Task.java:348)
        at org.apache.tools.ant.Target.execute(Target.java:435)
        at org.apache.tools.ant.Target.performTasks(Target.java:456)
        at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1393)
        at org.apache.tools.ant.Project.executeTarget(Project.java:1364)
        at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:41)
        at org.apache.tools.ant.Project.executeTargets(Project.java:1248)
        at org.apache.tools.ant.Main.runBuild(Main.java:851)
        at org.apache.tools.ant.Main.startAnt(Main.java:235)
        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: java.lang.ClassNotFoundException: org.apache.tomcat.util.codec.binary
.Base64
        at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
        ... 19 more

When I tried to find the class Base64 in the package org\apache\tomcat\util\codec\binary\ which is in tomcat-util.jar, and it is in the classpath which I've verified by an echo in Ant build file.

I'm not able to solve the issue.

like image 981
vvekselva Avatar asked Jan 06 '14 11:01

vvekselva


1 Answers

Just in case someone runs into the same problem I was having:

I was following the tutorial on the Tomcat website and I ran into the same NoClassDefFoundError issue when I tried to run ant install.

The tutorial mentions that you have to copy $CATALINA_HOME/lib/catalina-ant.jar1 (which contains the implementation code for the Ant custom tasks) to the lib directory of your Ant installation.

It does not mention, however, that you need to do the same thing for tomcat-util.jar. As soon as I copied tomcat-util.jar to my Ant directory, things started working (source).

1$CATALINA_HOME is the directory of your Tomcat installation, e.g. /usr/share/tomcat8

like image 198
Stefan van den Akker Avatar answered Sep 28 '22 03:09

Stefan van den Akker