Reputation: 499
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
Upvotes: 3
Views: 11696
Reputation: 499
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.
Upvotes: 3
Reputation: 20862
You need to be smarter about your <taskdef>
s:
<property name="catalina.home" value="/path/to/tomcat" />
<path id="tomcat.classpath">
<fileset dir="${catalina.home}" includes="lib/*.jar" />
</path>
.
.
.
<taskdef name="deploy"
classname="org.apache.catalina.ant.DeployTask"
classpathref="tomcat.classpath" />
You shouldn't have any of Tomcat's JAR files in your project's WEB-INF/lib
directory: remove them all.
Finally, getting more information from ant is easy: run ant --help
to see what debugging options you have.
Upvotes: 1
Reputation: 77961
This sounds like a runtime error. The missing class is part of the "tomcat-coyote.jar", are you sure it has been copied properly into your war file?
Check the wAR files contents as follows:
unzip -t myapp.war | more
The jars should all be located under the "WEB-INF/lib" directory. Anywhere else means they're not included on the classpath and would explain this error
Upvotes: 0