Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoClassDefFoundError: org/apache/tomcat/util/codec/binary/Base64

Still trying to make heads or tails of the hopelessly out-of-date official spring tutorial.

This time, it's the error in subject:

c:\Users\mkumpan\Projects\Spring testing\build.xml:152: java.lang.NoClassDefFoundError: org/apache/tomcat/util/codec/binary/Base64
<stack trace dump omitted>

This class is actually contained in tomcat-util.jar:

bash-3.1$ pwd
/c/Program Files/Tomcat/lib
bash-3.1$ jar -tf ./tomcat-util.jar | grep Base64
org/apache/tomcat/util/codec/binary/Base64.class

And I'm pretty darn sure that I included it in build.xml:

<fileset dir="${appserver.home}/bin">
    <include name="*.jar"/>
</fileset>

I even tried to be more explicit:

<fileset dir="C:\Program Files\Tomcat\lib\" includes="tomcat-util.jar">

Nothing works, I still get that message every time I try to run any tomcat-related targets. Could someone, perhaps, suggest a line of investigation?

Google doesn't seem to provide anything relevant.

Update: Full master-classpath reference provided below.

<path id="master-classpath">
    <fileset dir="${web.dir}/WEB-INF/lib">
        <include name="*/*.jar"/>
    </fileset>

    <fileset dir="${appserver.lib}">
        <include name="*.jar"/>
    </fileset>

    <fileset dir="${appserver.home}/bin">
        <include name="*.jar"/>
    </fileset>

    <pathelement path="${build.dir}"/>
</path>
like image 753
Maxim Kumpan Avatar asked Sep 10 '13 10:09

Maxim Kumpan


2 Answers

The wrong pathref was used for the necessary targets, one that did not contain a path to the much-needed tomcat-util.jar.

Kudos to @akostadinov for the prod in the right direction.

like image 137
Maxim Kumpan Avatar answered Oct 06 '22 06:10

Maxim Kumpan


If you use the following tomcat related entries in build.xml and build.properties the ant deployment should work in tomcat 7 and above

<!-- ============================================================== -->
<!-- Tomcat tasks - remove these if you don't have Tomcat installed -->
<!-- ============================================================== -->

<path id="catalina-ant-classpath">
    <!-- We need the Catalina jars for Tomcat -->
    <!--  * for other app servers - check the docs -->
    <fileset dir="${appserver.lib}">
        <include name="catalina-ant.jar"/>
        <include name="tomcat-util.jar"/>
    </fileset>
</path>

<taskdef name="install" classname="org.apache.catalina.ant.DeployTask">
    <classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask">
    <classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="list" classname="org.apache.catalina.ant.ListTask">
    <classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="start" classname="org.apache.catalina.ant.StartTask">
    <classpath refid="catalina-ant-classpath"/>
</taskdef>
<taskdef name="stop" classname="org.apache.catalina.ant.StopTask">
    <classpath refid="catalina-ant-classpath"/>
</taskdef>

<target name="install" description="Install application in Tomcat">
    <install url="${tomcat.manager.url}"
             username="${tomcat.manager.username}"
             password="${tomcat.manager.password}"
             path="/${name}"
             war="${name}"/>
</target>

<target name="reload" description="Reload application in Tomcat">
    <reload url="${tomcat.manager.url}"
             username="${tomcat.manager.username}"
             password="${tomcat.manager.password}"
             path="/${name}"/>
</target>

<target name="start" description="Start Tomcat application">
    <start url="${tomcat.manager.url}"
             username="${tomcat.manager.username}"
             password="${tomcat.manager.password}"
             path="/${name}"/>
</target>

<target name="stop" description="Stop Tomcat application">
    <stop url="${tomcat.manager.url}"
             username="${tomcat.manager.username}"
             password="${tomcat.manager.password}"
             path="/${name}"/>
</target>

<target name="list" description="List Tomcat applications">
    <list url="${tomcat.manager.url}/text"
             username="${tomcat.manager.username}"
             password="${tomcat.manager.password}"/>
</target>

<!-- End Tomcat tasks -->

and also make sure following entries are added in tomcat-users.xml in tomcat installation/conf dir

  <role rolename="manager-gui"/>
  <role rolename="admin-gui"/>
  <role rolename="manager"/>
  <role rolename="manager-script"/>
  <user username="kanchan" password="kanchan" roles="manager,manager-gui,admin-gui,manager-script"/>
like image 40
kanchan Avatar answered Oct 06 '22 07:10

kanchan