我在Eclipse上使用Hibernate并在尝试编译时不断收到以下错误消息:
build.xml:39:java.lang.NoClassDefFoundError:org / apache / commons / logging / LogFactory
我的libs文件夹中有commons-logging.jar
文件,这是我的classpath文件:
<?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="<annotated-types/>" />
<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 :(得分:0)
我认为您可能需要提供有关项目结构的更多详细信息。你是如何打包你的项目的? (它是否包含带有ejb模块封装的耳朵......)
很明显它是一个类加载问题。或者jar可能没有与最终可部署存档一起打包。解决方案最简单的方法是将common-logging.jar文件复制并粘贴到服务器的lib目录中。 (对于tomcat我相信它在catalina_home文件夹下......但我不确定)答案 1 :(得分:0)
您似乎已发布了Eclipse的.classpath
元数据文件的内容,该文件定义了Eclipse在Eclipse 中构建项目时使用的类路径,但您还提到使用{{1}这意味着你也在使用Ant从IDE外部构建项目。
确保build.xml
中的<javac>
个任务也引用build.xml
;除非您以某种方式配置构建脚本来执行此操作(可能通过从Eclipse生成build.xml),否则Ant将不会使用commons-logging.jar
文件。