I am using Hibernate on Eclipse and continually get the following error message when I try to compile:
build.xml:39: java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
I have the commons-logging.jar
file inside my libs folder, and here is my classpath file:
<?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>
I even tried printing the class path from within the build.xml
file, and the commons-logging.jar
appears within there as well, with the correct directory. Here is my build.xml file for further reference:
<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 c开发者_如何学JAVAlasspath="${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>
I think you might have to provide more details on your project structure. How did you package your project? (Does it contain an ear with ejb module packaged...)
Pretty obviously its a class loading problem. Or it is possible that the jar is not packaged with the final deployable archive. The easiest fix for your solution is to copy and paste the common-logging.jar file in to your server's lib directory. (for tomcat I believe its under catalina_home folder.. but I am not sure)
You seem to have posted the contents of Eclipse's .classpath
metadata file, which defines the classpath that Eclipse uses when building your project within Eclipse, but you also mention using build.xml
which implies you are also using Ant to build the project externally from the IDE.
Make sure your <javac>
tasks in build.xml
also refer to commons-logging.jar
; the .classpath
file will not be used by Ant unless you have somehow configured the build script to do so (possibly by generating build.xml from Eclipse).
精彩评论