简体   繁体   中英

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>

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.

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"/>

For anyone that might stumble upon this issue with tomcat 7. It looks as if org/apache/tomcat/util/codec/binary/Base64 was added into tomcat-coyote.jar in version 7.0.39.

So I think the options:

  • update to 7.0.39+
  • use it from somewhere else org/apache/commons/codec/binary/Base64 (commons-codec:commons-codec)

在Tomcat 8中,相关的库似乎是“tomcat-util.jar”而不是tomcat-coyote :-)

For tomcat version 7 and above, just include tomcat-util.jar in your build.xml file

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM