build error in eclipse(helios) for dynamic web project
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开发者_Python百科 which will just print the uname. I am using Ant to build the war and deploy.
I have done below settings for path:
- ANT_HOME = C:\apache-ant-1.7.0
- JAVA_HOME = C:\java\jdk1.6
- classpath = .;%JAVA_HOME%\lib;%ANT_HOME%\lib
- 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>
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.
精彩评论