在编译Servlet文件的时候出错:软件包 javax.servlet 不存在
解决方法:
方法(1) 找到%tomcat%\common\lib目录下的servlet-api.jar,把这个路径添加到环境变量classpath当中,就可以了。(这个好像不是很管用,我重装了tomcat之后,再重新配置好像就不行了)
方法(2) 找到%tomcat%\common\lib目录下的servlet-api.jar,把这个jar添加到%java_home%/\jdk1.6.0\jre\lib\ext目录下面,不同的jdk版本都一样。
方法三:
引入环境变量
片段
<!--tomcathome-->
<property name="tomcathome" location="${SystemVariable.TOMCAT_HOME}"/>
<!--编译Plat用的classpath-->
<path id="classpath">
<fileset dir="${lib}">
<include name="*.jar"/>
</fileset>
<fileset dir="${tomcathome}/lib">
<include name="*.jar"/>
</fileset>
</path>
<javac srcdir="${basedir}/src;${basedir}/patch/spring" destdir="${classes}" includeantruntime="false" bootclasspath="${java.home}/lib/rt.jar" >
<classpath refid="classpath"/>
<compilerarg value="-g:lines,vars,source" />
</javac>
软件包 javax.servlet.jsp 不存在
同样方法解决,拷贝jsp-api.jar
最好把el-api.jar一并考过去,否则运行项目会报异常
java.lang.ClassNotFoundException: javax.el.ELResolver
一个例子:
<!-- ================== -->
<!-- === PROPERTIES === -->
<!-- ================== -->
<property name="lib.dir" value="./WebRoot/WEB-INF/lib" />
<property name="JBOSS_HOME" value="D:/jboss-4.0.5.GA/server/default/deploy" />
<property name="JBOSS_LIB1" value="D:/jboss-4.0.5.GA/server/default/lib" />
<property name="JBOSS_LIB2" value="D:/jboss-4.0.5.GA/lib" />
<!-- ================= -->
<!-- === CLASSPATH === -->
<!-- ================= -->
<path id="classpath">
<fileset dir="${lib.dir}" includes="*.jar,*.zip" />
<fileset dir="${JBOSS_LIB1}" includes="*.jar" />
<fileset dir="${JBOSS_LIB2}" includes="*.jar" />
</path>
<!-- =============== -->
<!-- === COMPILE === -->
<!-- =============== -->
<target name="compile" description="compiles the server classes">
<mkdir dir="${build.dir}" />
<javac srcdir="${src.dir}" destdir="${build.dir}">
<classpath refid="classpath" />
</javac>
<copy todir="${build.dir}">
<fileset dir="${src.dir}">
<include name="**/*.xml"/>
<include name="**/*.properties"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>