2011-07-11 57 views
0

我使用Eclipse的休眠,当我尝试编译不断收到以下错误信息:日志厂错误

build.xml:39: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory

我有commons-logging.jar文件我libs文件夹内,这里是我的类路径文件:

<?xml version="1.0" encoding="UTF-8"?> 
<classpath> 
    <classpathentry kind="src" path="src"/> 
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"> 
     <attributes> 
      <attribute name="owner.project.facets" value="java"/> 
     </attributes> 
    </classpathentry> 
    <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v6.0"> 
     <attributes> 
      <attribute name="owner.project.facets" value="jst.web"/> 
     </attributes> 
    </classpathentry> 
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/> 
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/> 
    <classpathentry kind="src" path="flex_src"/> 
    <classpathentry kind="output" path="build/classes"/> 
</classpath> 

我甚至尝试从build.xml文件中打印的类路径和commons-logging.jar出现内有作为,有正确的目录。这里是我的build.xml文件供进一步参考:

<project name="project" default="main"> 
    <property file="build.properties" /> 
    <xmlproperty file="${project-root}/src/META-INF/persistence.xml" collapseAttributes="true" /> 
    <description>Generate CDB files</description> 
    <target name="force"> 
     <property name="force.build" value="true" /> 
     <antcall target="mainInternal" /> 
    </target> 
    <target name="main"> 
     <property name="force.build" value="false" /> 
     <antcall target="mainInternal" /> 
    </target> 
    <target name="mainInternal"> 
     <antcall target="generateHibernateCfg" /> 
     <antcall target="compileEntities" /> 
     <antcall target="findAnnotations" /> 
     <antcall target="compileServiceInterfaces" /> 
     <antcall target="generateDTOs" /> 
     <antcall target="generateServices" /> 
     <antcall target="generateFlex" /> 
     <antcall target="generateBlazeDSConfig" /> 
    </target> 
    <target name="generateHibernateCfg"> 
     <xslt in="${project-root}/src/META-INF/persistence.xml" style="${project-root}/cdb_build/src/hibernate.cfg.xsl" out="${project-root}/src/hibernate.cfg.xml" force="${force.build}" /> 
    </target> 
    <target name="compileEntities"> 
     <path id="build.class.path"> 
      <fileset dir="${project-root}/WebContent/WEB-INF/lib" /> 
      <pathelement path="${classes-folder}" /> 
     </path> 
     <pathconvert property="cp" refid="build.class.path" /> 
     <echo message="Classpath = ${cp}"/> 
     <path id="srcfiles"> 
      <fileset dir="${project-root}/src"> 
       <include name="**/*.java" /> 
      </fileset> 
     </path> 
     <pathconvert property="srcfiles" refid="srcfiles" pathsep=" " /> 
     <script language="javascript"> 
      <![CDATA[ 
      var includes = ""; 
      var entitiesString = project.getProperty("persistence.persistence-unit.class"); 
      if (entitiesString) { 
       var entities = entitiesString.split(","); 
       for (entity in entities) { 
        if (entities[entity] != null && entities[entity] != "") { 
         includes += String(entities[entity]).replace(/\./g, '/') + ".java,"; 
        } 
       } 
      } 
      project.setProperty("entities.include", includes); 
      ]]> 
     </script> 
     <mkdir dir="${project-root}/build/classes" /> 
     <javac includes="${entities.include}" srcdir="${project-root}/src" destdir="${classes-folder}" classpath="${cp}" debug="on" /> 
    </target> 
    <target name="findAnnotations"> 
     <file name="annotated.xml" id="annotated.xml" /> 
     <echo file="annotated.xml" message="&lt;annotated-types/&gt;" /> 
     <path id="build.class.path"> 
      <fileset dir="${project-root}/WebContent/WEB-INF/lib" /> 
      <pathelement path="${classes-folder}" /> 
     </path> 
     <pathconvert property="cp" refid="build.class.path" /> 
     <path id="srcfiles"> 
      <fileset dir="${project-root}/src"> 
       <include name="**/*.java" /> 
      </fileset> 
     </path> 
     <pathconvert property="srcfiles" refid="srcfiles" pathsep=" " /> 
     <path id="cfg-xml-path"> 
      <fileset file="${project-root}/src/hibernate.cfg.xml" /> 
     </path> 
     <pathconvert property="cfg-xml" refid="cfg-xml-path" /> 
     <apt classpath="${cp}" 
      compile="false" 
      factory="com.farata.cdb.annotations.processor.CDBFullAnnotationProcessor" 
      srcdir="${project-root}/src" 
      sourcepath="${project-root}/src"> 
      <option name="com.faratasystems.cdb.annotations.file" value="annotated.xml"/> 
      <option name="com.faratasystems.cdb.configuration.file" value="${cfg-xml}"/> 
      <include name="**/*.java"/> 
     </apt> 
    </target> 
    <target name="compileServiceInterfaces"> 
     <path id="build.class.path"> 
      <fileset dir="${project-root}/WebContent/WEB-INF/lib" /> 
      <pathelement path="${classes-folder}" /> 
     </path> 
     <pathconvert property="cp" refid="build.class.path" /> 
     <path id="srcfiles"> 
      <fileset dir="${project-root}/src"> 
       <include name="**/*.java" /> 
      </fileset> 
     </path> 
     <pathconvert property="srcfiles" refid="srcfiles" pathsep=" " /> 
     <xmlproperty file="annotated.xml" collapseAttributes="true" /> 
     <script language="javascript"> 
      <![CDATA[ 
      var includes = ""; 
      var typeNamesString = project.getProperty("annotated-types.annotated-type.name"); 
      if (typeNamesString) { 
       var annotationNamesString = project.getProperty("annotated-types.annotated-type.annotations.annotation.name"); 
       var annotationNames = annotationNamesString.split(","); 
       var typeNames = typeNamesString.split(","); 
       for (annotationName in annotationNames) { 
        if (annotationNames[annotationName] != null && annotationNames[annotationName] != "") { 
         if (annotationNames[annotationName] == "clear.cdb.annotations.CX_Service") { 
          includes += String(typeNames[annotationName]).replace(/\./g, '/') + ".java,"; 
         } 
        } 
       } 
      } 
      project.setProperty("entities.include", includes); 
      ]]> 
     </script> 
     <javac includes="${entities.include}" srcdir="${project-root}/src" destdir="${classes-folder}" classpath="${cp}" debug="on" /> 
    </target> 
    <target name="generateDTOs"> 
     <xmlproperty file="annotated.xml" collapseAttributes="true" /> 
     <path id="build.class.path"> 
      <fileset dir="${project-root}/WebContent/WEB-INF/lib" /> 
      <pathelement path="${classes-folder}" /> 
     </path> 
     <pathconvert property="cp" refid="build.class.path" /> 
     <path id="srcfiles"> 
      <fileset dir="${project-root}/src"> 
       <include name="**/*.java" /> 
      </fileset> 
     </path> 
     <pathconvert property="srcfiles" refid="srcfiles" pathsep=" " /> 
     <xslt classpathref="build.class.path" in="annotated.xml" style="src/service-dto-all.xsl" out="tmp.txt" force="true"> 
      <param name="outputFolder" expression="${project-root}src" /> 
      <param name="force" expression="${force.build}" /> 
     </xslt> 
     <script language="javascript" src="${basedir}/scripts.js"> 
      <![CDATA[ 
       var includes = getServicesDTOs(); 
       includes += getServicesDTOSubclasses(); 
       project.setProperty("entities.include", includes == ""? "none":includes); 
      ]]> 
     </script> 
     <javac includes="${entities.include}" srcdir="${project-root}/src" destdir="${classes-folder}" classpath="${cp}" debug="on" failonerror="false" /> 
    </target> 
    <target name="generateServices"> 
     <xmlproperty file="annotated.xml" collapseAttributes="true" /> 
     <path id="build.class.path"> 
      <fileset dir="${project-root}/WebContent/WEB-INF/lib" /> 
      <pathelement path="${classes-folder}" /> 
     </path> 
     <pathconvert property="cp" refid="build.class.path" /> 
     <path id="srcfiles"> 
      <fileset dir="${project-root}/src"> 
       <include name="**/*.java" /> 
      </fileset> 
     </path> 
     <pathconvert property="srcfiles" refid="srcfiles" pathsep=" " /> 
     <xslt classpathref="build.class.path" in="annotated.xml" style="src/service-impl-all.xsl" out="tmp.txt" force="true"> 
      <param name="outputFolder" expression="${project-root}src" /> 
      <param name="force" expression="${force.build}" /> 
     </xslt> 
     <script language="javascript" src="${basedir}/scripts.js"> 
      <![CDATA[ 
      var includes = getServices(); 
      includes += getServicesSubclasses(); 
      project.setProperty("entities.include", includes == ""? "none":includes); 
      ]]> 
     </script> 
     <javac includes="${entities.include}" srcdir="${project-root}/src" destdir="${classes-folder}" classpath="${cp}" debug="on" /> 
    </target> 
    <target name="generateFlex"> 
     <xmlproperty file="annotated.xml" collapseAttributes="true" /> 
     <path id="build.class.path"> 
      <fileset dir="${project-root}/WebContent/WEB-INF/lib" /> 
      <pathelement path="${classes-folder}" /> 
     </path> 
     <pathconvert property="cp" refid="build.class.path" /> 
     <path id="srcfiles"> 
      <fileset dir="${project-root}/src"> 
       <include name="**/*.java" /> 
      </fileset> 
     </path> 
     <pathconvert property="srcfiles" refid="srcfiles" pathsep=" " /> 
     <xslt classpathref="build.class.path" in="annotated.xml" style="flex_src/flex-all.xsl" out="tmp.txt" force="true"> 
      <param name="flexOutputFolder" expression="${flex-output-folder}" /> 
      <param name="javaSrcFolder" expression="${project-root}src" /> 
      <param name="force" expression="${force.build}" /> 
     </xslt> 
     <xslt classpathref="build.class.path" in="annotated.xml" style="flex_src/application-all.xsl" out="tmp.txt" force="true"> 
      <param name="javaSrcFolder" expression="${project-root}src" /> 
      <param name="testFolder" expression="${project-root}test" /> 
      <param name="force" expression="${force.build}" /> 
     </xslt> 
    </target> 
    <target name="generateBlazeDSConfig"> 
     <xmlproperty file="annotated.xml" collapseAttributes="true" /> 
     <path id="build.class.path"> 
      <fileset dir="${project-root}/WebContent/WEB-INF/lib" /> 
      <pathelement path="${classes-folder}" /> 
     </path> 
     <pathconvert property="cp" refid="build.class.path" /> 
     <path id="srcfiles"> 
      <fileset dir="${project-root}/src"> 
       <include name="**/*.java" /> 
      </fileset> 
     </path> 
     <pathconvert property="srcfiles" refid="srcfiles" pathsep=" " /> 
     <script language="javascript" src="${basedir}/scripts.js"> 
      <![CDATA[ 
      generateRemotingConfig(); 
      generateMessagingConfig(); 
      ]]> 
     </script> 
    </target> 
</project> 

回答

0

我想你可能需要提供更多关于你的项目结构的细节。你是如何打包你的项目的? (它是否包含ejb模块封装的耳朵......)

很明显它是一个类加载问题。或者,jar可能没有与最终的可部署归档一起打包。解决方案最简单的解决方法是将common-logging.jar文件复制并粘贴到服务器的lib目录中。 (Tomcat的,我相信它的CATALINA_HOME文件夹下..但我不知道)

+0

不幸的是,我已经尝试将jar复制到服务器的lib目录中,但没有运气 –

+0

如何在服务器中部署此项目?你打开了可部署的存档吗? (解压缩..)你有没有找到common.loggin.jar。可能你有一个不同版本的jar文件。你是否也可以打开common.logging.jar文件并查看包“org.apache.common.logging”是否存在。 –

+0

包确实存在于jar文件中。我也不确定您的可部署归档文件的含义。在脱机构建文件的过程中,我收到了这些错误,没有涉及Tomcat。这不妨碍它成为服务器问题吗? –

0

你似乎已经发布了Eclipse的.classpath元数据文件,它定义了类路径Eclipse使用Eclipse内建设项目时的内容,但你也提到使用build.xml这意味着你也使用Ant从IDE外部构建项目。

确保您在build.xml中的<javac>任务也参考commons-logging.jar; .classpath文件将不会被Ant使用,除非您以某种方式配置了构建脚本(可能通过从Eclipse生成build.xml)。

+0

它们似乎也指commons-logging.jar。我将build.xml文件发布到问题中以供参考。 –