servlet action抛出异常:java.lang.ClassNotFoundException:org.dom4j.DocumentException当通过ANT构建脚本

时间:2015-12-23 22:01:55

标签: ant jar apache-poi classnotfoundexception web-inf

我的项目使用ant build脚本创建WEB_INF / lib文件夹并将所有jar文件复制到其中,当我运行build.xml时,创建的war文件包含所有jar的WEB_INF / lib文件夹,我有以下错误在运行时:

servlet action threw exception: java.lang.ClassNotFoundException: org.dom4j.DocumentException

但是,如果我手动创建WEB_INF / lib文件夹并将dom4j.jar放入其中,并运行相同的build.xml,则一切正常,并且没有此类错误。

我的build.xml文件是:

    <project name="hrperf" default="compile">

  <property environment="env"/>

  <!-- HUDSON properties -->
  <property name="project.build.no" value="${env.BUILD_NUMBER}"/>

  <!-- project properties -->
  <property name="project.name" value="${ant.project.name}"/>
  <property name="project.version" value="6.3.7"/>

  <!-- build file debug properties [on|off] -->
  <property name="build.debug" location="on"/>

  <!-- path properties -->
  <property name="src.dir" location="src"/>
  <property name="src.resources.dir" location="${src.dir}/com/bchydro/hrperf/resources"/>
  <property name="lib.dir" location="lib"/>
  <property name="build.dir" location="build"/>
  <property name="build.classes.dir" location="${build.dir}/classes"/>
  <property name="dist.dir" location="dist"/>
  <property name="bin.dir" location="bin"/>
  <property name="dist.wartemp.dir" location="${dist.dir}/wartemp"/>
  <property name="dist.wartemp.web-inf.dir" location="${dist.wartemp.dir}/WEB-INF"/>
  <property name="dist.wartemp.web-inf.classes.dir" location="${dist.wartemp.web-inf.dir}/classes"/>
  <property name="dist.wartemp.web-inf.lib.dir" location="${dist.wartemp.web-inf.dir}/lib"/>
  <property name="dist.wartemp.resources.dir" location="${dist.wartemp.web-inf.classes.dir}/com/bchydro/hrperf/resources"/>
  <property name="defaultroot.dir" location="defaultroot"/>
  <property name="db.server.token" value="&lt;set-property property=&quot;url&quot; value=&quot;jdbc:oracle:thin:@EDMEXORCT1:1521:EXWEBTST&quot; /&gt;"/>
  <property name="db.username.token" value="&lt;set-property property=&quot;username&quot; value=&quot;compauth_dev&quot; /&gt;"/>
  <property name="db.password.token" value="&lt;set-property property=&quot;password&quot; value=&quot;compauth_dev1&quot; /&gt;"/>

  <!-- Test classpath properties -->
  <property name="test.dir" location="${build.dir}/test"/>
  <property name="test.data.dir" location="${test.dir}/data"/>
  <property name="test.reports.dir" location="${test.dir}/reports"/>
  <property name="javadocs.dir" value="${test.reports.dir}/javadocs"/>
  <property name="lib.junit.dir" location="${lib.dir}/junit-3.8.1"/>
  <property name="junit.jar" value="${lib.junit.dir}/junit.jar"/>

  <!-- application properties -->
  <property name="warfile.name" value="${project.name}-${project.version}.${project.build.no}"/>
<!--  <property name="warfile.region" value="-DEV"/>-->
  <property name="warfile.ext" value=".war"/>
  <property name="hrperf.properties.name" value="hrperf.properties"/>
  <property name="hrperf.messages.name" value="messages.properties"/>
  <property name="log4j.properties.name" value="log4j.properties"/>
  <property name="struts-config.xml.name" value="struts-config.xml"/>
  <property name="struts-db.xml.name" value="struts-db.xml"/>
  <property name="crconfig.xml.name" value="CRConfig.xml"/>
  <property name="package.name" value="hrperf" />

  <!-- lib path properties -->
  <property name="servlet.jar" value="${lib.servlet.dir}/servlet.jar"/>
  <property name="lib.dbcp.dir" location="${lib.dir}/commons-dbcp-1.4"/>
  <property name="lib.pool.dir" location="${lib.dir}/commons-pool-1.6"/>
  <property name="lib.log4j.dir" location="${lib.dir}/jakarta-log4j-1.2.8"/>
  <property name="lib.struts.dir" location="${lib.dir}/jakarta-struts-1.2.6"/>
  <property name="lib.jdbc.dir" location="${lib.dir}/jdbc"/>
  <property name="lib.jstl.dir" location="${lib.dir}/jstl"/>
  <property name="lib.mail.dir" location="${lib.dir}/mail"/>
  <property name="lib.servlet.dir" location="${lib.dir}/servlet"/>
  <property name="lib.displaytag.dir" location="${lib.dir}/displaytag-1.0"/>
  <property name="lib.jfreecharttag.dir" location="${lib.dir}/jfreechart"/>
  <property name="lib.cewolf.dir" location="${lib.dir}/cewolf"/>
  <property name="lib.crystal.dir" location="${lib.dir}/crystal"/>
  <property name="lib.cloning.dir" location="${lib.dir}/cloning-1.9.0"/>
  <property name="lib.cobertura.dir" location="${lib.dir}/cobertura-1.8"/>
  <property name="lib.poi.dir" location="${lib.dir}/poi-3.9"/>  
  <property name="lib.commons-fileupload.dir" location="${lib.dir}/commons-fileupload"/>
  <property name="lib.commons-io.dir" location="${lib.dir}/commons-io"/>
  <property name="lib.commons-collections.dir" location="${lib.dir}/commons-collections"/>
  <property name="lib.dom4j.dir" location="${lib.dir}/dom4j-1.6.1"/>
  <property name="lib.gson.dir" location="${lib.dir}/gson"/>

  <!-- classpath properties -->
  <property name="log4j.jar" value="${lib.log4j.dir}/log4j-1.2.8.jar"/>
  <property name="struts.jar" value="${lib.struts.dir}/struts.jar"/>
  <property name="jstl.jar" value="${lib.jstl.dir}/jstl.jar"/>
  <property name="standard.jar" value="${lib.jstl.dir}/standard.jar"/>
  <property name="mail.jar" value="${lib.mail.dir}/mail.jar"/>
  <property name="displaytag.jar" value="${lib.displaytag.dir}/displaytag-1.0.jar"/>
  <property name="jfreecharttag.jar" value="${lib.jfreecharttag.dir}/jfreechart-1.0.0-rc1.jar"/>
  <property name="jcommon.jar" value="${lib.jfreecharttag.dir}/jcommon-1.0.0-rc1.jar"/>
  <property name="cewolf.jar" value="${lib.cewolf.dir}/cewolf.jar"/>
  <property name="dom4j.jar" value="${lib.dom4j.dir}/dom4j-1.6.1.jar"/>
  <property name="gson-2.2.4-sources.jar" value="${lib.gson.dir}/gson-2.2.4-sources.jar"/>
  <property name="gson-2.2.4.jar" value="${lib.gson.dir}/gson-2.2.4.jar"/>

  <!-- Classpath properties -->
  <property name="cobertura.jar" value="${lib.cobertura.dir}/cobertura-1.8.jar"/>

  <!-- cobertura serialized filename -->
  <property name="cobertura.ser.name" value="${test.data.dir}/cobertura.ser"/>

  <!-- Crystal Reports Libraries -->
  <property name="cloning.jar" value="${lib.cloning.dir}/*.jar"/>
  <property name="crystal.jar" value="${lib.crystal.dir}/*.jar"/>

  <!--
    =======================================================================
    Classpaths
    =======================================================================
  -->
  <!-- compile classpath -->
  <path id="compile.classpath">
    <pathelement location="${log4j.jar}"/>
    <pathelement location="${struts.jar}"/>
    <pathelement location="${jstl.jar}"/>
    <pathelement location="${standard.jar}"/>
    <pathelement location="${servlet.jar}"/>
    <pathelement location="${mail.jar}"/>
    <pathelement location="${displaytag.jar}"/>
    <pathelement location="${jfreecharttag.jar}"/>
    <pathelement location="${jcommon.jar}"/>
    <pathelement location="${cewolf.jar}"/>
    <pathelement location="${dom4j.jar}"/>
    <pathelement location="${gson-2.2.4-sources.jar}"/>
    <pathelement location="${gson-2.2.4.jar}"/>
    <!-- Crystal Reports jar files -->
    <pathelement location="${crystal.jar}"/>
    <fileset dir="lib">
      <include name="**/*.jar"/>
    </fileset>
  </path>

  <!-- Test classpath -->
  <path id="test.classpath">
    <path refid="compile.classpath" />
    <pathelement location="${junit.jar}"/>
    <pathelement location="${build.dir}/classes"/>
    <pathelement location="${build.dir}/test"/>
  </path>

  <!-- Cobertura classpath -->
  <path id="cobertura.classpath">
    <path refid="test.classpath"/>
    <fileset dir="${lib.log4j.dir}" includes="**/*.jar"/>
    <fileset dir="${lib.cobertura.dir}" includes="**/*.jar"/>
  </path>

创建war文件的任务如下:

 <!-- STAGING -->
  <target name="staging" depends="packageinit">
    <!-- Load Application Properties File -->
    <property file="${src.resources.dir}/hrperf.staging.properties" />

    <!-- copy struts DB file -->
    <copy file="${dist.wartemp.web-inf.dir}/struts-db-staging.xml" tofile="${dist.wartemp.web-inf.dir}/${struts-db.xml.name}" overwrite="true"/>
    <!-- remove development, staging, esc and production struts-db files -->
    <delete>
        <fileset dir="${dist.wartemp.web-inf.dir}" includes="*-development.xml, *-staging.xml, *-esc.xml, *-production.xml"/>
    </delete>

    <!-- copy resource files -->
    <copy file="${src.resources.dir}/hrperf.staging.properties"     tofile="${dist.wartemp.resources.dir}/${hrperf.properties.name}"/>
    <copy file="${lib.log4j.dir}/log4j.staging.properties" tofile="${dist.wartemp.web-inf.classes.dir}/${log4j.properties.name}" overwrite="true"/>

    <property name="warfile.region" value="-test"/>
    <antcall target="warfinal"/>
  </target>
你可以给我建议解决这个问题吗? 谢谢,

0 个答案:

没有答案