0

I have a simple dynamic web project in eclipse(helios). In this I have one jsp which ask for uname and password and it goes to a servlet which will just print the uname. I am using Ant to build the war and deploy.

I have done below settings for path:

  1. ANT_HOME = C:\apache-ant-1.7.0
  2. JAVA_HOME = C:\java\jdk1.6
  3. classpath = .;%JAVA_HOME%\lib;%ANT_HOME%\lib
  4. path = %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%JAVA_HOME%\bin;%Path%;%ANT_HOME%\bin

tomcat is installed at c:\tomcat

I have following files in WEB-INF\lib

jstl-1.1.2.jar, jstl.jar, servlet-api.jar, standard-1.0.6.jar

Now, when I am trying to do the ant build it gives me compilation errors, errors are as below: package javax.servlet.http does not exist, package javax.servlet.http does not exist, package javax.servlet.http does not exist and so on

can anyone help me with the problem ? Is problem with the classpath or it is not able to find the jar ?

Thanks

Build file

<property name="build.dir" value="build" />
<property name="src.dir" value="src" />
<property name="dist.dir" value="c:\tomcat\webapps" />
<property name="jardir.dir" value="C:\tomcat\common\lib" />

<target name="clean" description="Removes temporary directories">
    <delete dir="${build.dir}" />
    <delete dir="bin" failonerror="false" />
    <delete dir="${dist.dir}/jar" failonerror="false" />
    <delete dir="${dist.dir}/FirstTestApp" failonerror="false"/>
</target>

<target name="init" description="Creates temporary directories">
    <mkdir dir="${build.dir}/classes" />
    <mkdir dir="${dist.dir}" />
</target>   

<target name="compile" depends="init"  description="compiles files">
    <javac debug="true" deprecation="true"
    destdir="${build.dir}/classes" srcdir="${src.dir}"
    verbose="true" classpath="${jardir.dir}" />
</target>   

<target name="war" depends="compile">
    <war destfile="${dist.dir}\FirstTestApp.war" basedir="${build.dir}" webxml="web\WEB-INF\web.xml">

        <lib dir="web/WEB-INF/lib" includes ="**/*.jar"/>                   

        <!--<fileset dir="web/jsp" includes="*.jsp" />-->

        <fileset dir="web" includes="js/**,images/**,css/**,jsp/**" />
    </war>
</target>

shiny
  • 43
  • 1
  • 11

1 Answers1

1

Ant doesn't know anything about web projects. It doesn't automatically include the jars in WEB-INF/lib in the classpath. You have to explicitely include all the required jars in the classpath used by the javac task to compile your classes.

Note that at least servlet-api.jar should not be in WEB-INF/lib, since it's obviously in tomcat's root classpath.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • I removed servlet-api.jar from WEB-INF/lib and checked the build path it has c:\tomcat\common\lib files. After this I tried to do the build again but same issue persist. – shiny Sep 26 '11 at 12:07
  • Ant and eclipse are two very different things. If you build with ant, it won't magically get the build path from Eclipse. As I wrote in my answer, you must define an explicit classpath in the javac task of your ant build file. Show us your ant build file. – JB Nizet Sep 26 '11 at 12:10
  • as you said I added the jar in the classpath for javac command in build.xml, but still it doesnt work. – shiny Sep 26 '11 at 12:23
  • I am attaching the build file have a look at it – shiny Sep 26 '11 at 12:24
  • The jar file itself must be in the classpath. Not just the directory containing the jar file. – JB Nizet Sep 26 '11 at 12:30
  • thanks @JB Nizet after including the jar file in the path build is successfull – shiny Sep 26 '11 at 12:35