Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying a simple web application to Tomcat using Ant

I am trying to deploy my simple web application which consists of one web servlet and a JSP. I haven't used any framework such as Spring or anything, just a helloWorld web app.

I am using Ant to for deployment purpose. But when I run my deploy target it gives me:

java.lang.NoClassDefFoundError: org/apache/tomcat/util/buf/B2CConverter

I am using Tomcat 7 and I have included all libraries under Tomcat lib directory and tomcat-juli.jar into my webcontent/web-inf/lib as well.

My Ant file targets are as follows:

<!-- Configure the directory into which the web application is built -->
    <property name="build" value="${basedir}/build" />
    <property name="lib.dir" value="${basedir}/WebContent/WEB-INF/lib" />
    <property name="src.dir" value="${basedir}/src" />

    <!-- Configure the context path for this application -->
    <property name="path" value="/myapp" />

    <!-- Configure properties to access the Manager application -->
    <property name="url" value="http://localhost:8080/manager/text" />
    <property name="username" value="gbids" />
    <property name="password" value="tomcat" />

    <!-- Configure the custom Ant tasks for the Manager application -->
    <taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask" />
    <taskdef name="list" classname="org.apache.catalina.ant.ListTask" />
    <taskdef name="reload" classname="org.apache.catalina.ant.ReloadTask" />
    <taskdef name="findleaks" classname="org.apache.catalina.ant.FindLeaksTask" />
    <taskdef name="resources" classname="org.apache.catalina.ant.ResourcesTask" />
    <taskdef name="start" classname="org.apache.catalina.ant.StartTask" />
    <taskdef name="stop" classname="org.apache.catalina.ant.StopTask" />
    <taskdef name="undeploy" classname="org.apache.catalina.ant.UndeployTask" />

<!-- Class path -->
    <path id="project.classpath">
        <fileset dir="${lib.dir}">
            <include name="**/*.jar" />
            <include name="**/*.zip" />
        </fileset>
    </path>

    <!-- Executable Targets -->
    <target name="compile" description="Compile web application">
        <javac srcdir="${src.dir}" destdir="${build}/classes" nowarn="on">
            <classpath refid="project.classpath" />
        </javac>

    </target>

    <target name="makeWar" depends="compile">
        <delete file="${build}${path}.war"/>
        <war destfile="${build}${path}.war" webxml="WebContent/WEB-INF/web.xml">
            <fileset dir="WebContent" />
            <lib dir="WebContent/WEB-INF/lib" />
            <classes dir="build/classes" />
        </war>
    </target>

    <target name="deploy" description="Install web application" depends="makeWar" >
        <deploy url="${url}" username="${username}" password="${password}" path="${path}" war="${build}${path}.war" />
    </target>


And I also have following in my tomcat-users.xml file:

  <role rolename="manager-gui"/>
  <role rolename="admin-gui"/>
  <role rolename="manager-script"/>

  <user username="manager" password="tomcat" roles="manager-gui"/>
  <user username="admin" password="tomcat" roles="admin-gui"/>
  <user username="gbids" password="tomcat" roles="manager-script"/>

Can anyone please help me to solve this problem.

Thanks

like image 992
gbids Avatar asked Nov 25 '25 12:11

gbids


1 Answers

I found the solution. I was trying to do that task according to the guidelines given in Tomcat documentation. According to that they ask only to copy 'catalina-ant.jar' file to Ant lib directory.

But once I have copied 'tomcat-coyote.jar' , 'tomcat-juli.jar' , 'tomcat-util.jar' files in to the Ant's lib directory together with 'catalina-ant.jar' file it worked perfectly for me.

like image 161
gbids Avatar answered Nov 27 '25 01:11

gbids



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!