当我尝试使用hibernate在数据库中重新创建表时,我收到此错误。
Exception in thread "main" java.lang.NoClassDefFoundError: classes/com/golf/model/Pupil (wrong name: com/golf/model/Pupil)
问题是,当我在执行ant之前重新创建表时,我可以在数据库中创建表而没有任何问题。但是在我使用ant执行build.xml文件之后,我收到了这个错误。
我的build.xml文件是这样的:
<project name="Golf" default="deploy" basedir=".">
<property name="name" value="Golf"/>
<property name="version" value="1.0"/>
<property name="project" value="Golf"/>
<property environment="env"/>
<property name="build.compiler" value="classic"/>
<property name="build.dir" value="../bin"/>
<property name="build.src" value="${build.dir}/src"/>
<property name="build.src.web" value="${build.dir}/src"/>
<property name="build.dest" value="${build.dir}/classes"/>
<property name="build.dest.web" value="${build.dir}/classes"/>
<property name="build.web" value="${build.dir}/web"/>
<property name="build.web-inf" value="${build.dir}/web/WEB-INF"/>
<property name="src.java.dir" value="../src"/>
<property name="web.src.java.dir" value="../src"/>
<property name="lib.dir" value="../lib"/>
<property name="compilelib.dir" value="../compile-lib"/>
<property name="devetc.dir" value="../etc"/>
<property name="web.dir" value="../web"/>
<property name="deliver.class" value="${deliver.dir}/WEB-INF/classes"/>
<property name="deliver.lib" value="${deliver.dir}/WEB-INF/lib"/>
<property name="distribution.dir" value="../distribution"/>
<property name="war.file.name" value="golf.war"/>
<property name="year" value="2012"/>
<property name="ant.home" value="."/>
<property name="debug" value="on"/>
<property name="optimize" value="off"/>
<property name="deprecation" value="off"/>
<target name="env">
<echo message="build.compiler = ${build.compiler}"/>
<echo message="java.class.path = ${java.class.path}"/>
<echo message="java.home = ${java.home}"/>
<echo message="user.home = ${user.home}"/>
<echo message="CATALINA.home = ${env.CATALINA_HOME}"/>
</target>
<patternset id="all.src.files">
<!-- All java files -->
<include name="**/*.java"/>
<!-- All conf files -->
<include name="**/*.xml"/>
<include name="**/*.properties"/>
<!-- All web files -->
<include name="**/*.jpg"/>
<include name="**/*.gif"/>
<include name="**/*.js"/>
<include name="**/*.jsp"/>
<include name="**/*.html"/>
</patternset>
<target name="prepare" depends="env">
<mkdir dir="${build.dir}"/>
<mkdir dir="${build.dest}"/>
<mkdir dir="${build.dest.web}"/>
<mkdir dir="${build.src}"/>
<mkdir dir="${build.web}"/>
<mkdir dir="${build.web-inf}"/>
<mkdir dir="${distribution.dir}"/>
<mkdir dir="${web.src.java.dir}"/>
<mkdir dir="${build.src.web}"/>
<filter token="version" value="${version}"/>
<copy todir="${build.src}" filtering="on">
<fileset dir="${src.java.dir}" >
<patternset refid="all.src.files"/>
</fileset>
</copy>
<copy todir="${build.web}">
<fileset dir="${web.dir}">
<include name="**/*.*"/>
<exclude name="**/*.bak"/>
</fileset>
</copy>
</target>
<target name="compile" depends="prepare">
<javac srcdir="${build.src.web}"
destdir="${build.dest.web}"
debug="${debug}"
deprecation="${deprecation}"
optimize="${optimize}">
<exclude name="**/package.html"/>
<exclude name="**/overview.html"/>
<classpath>
<path>
<fileset dir="${lib.dir}"/>
<fileset dir="${compilelib.dir}"/>
</path>
</classpath>
</javac>
<copy todir="${build.web-inf}">
<fileset dir="${devetc.dir}">
<exclude name="**/*.bak"/>
</fileset>
</copy>
<copy todir="${build.dest.web}">
<fileset dir="${web.src.java.dir}">
<include name="**/*.xml"/>
<include name="**/*.properties"/>
<exclude name="**/*.bak"/>
</fileset>
</copy>
</target>
<target name="deploy" depends="war">
<copy todir="${env.CATALINA_HOME}/webapps">
<fileset dir="${distribution.dir}">
<include name="*.war"/>
</fileset>
</copy>
</target>
<target name="war" depends="compile">
<war warfile="${distribution.dir}/${war.file.name}" webxml="${devetc.dir}/web.xml">
<fileset dir="${build.web}">
<exclude name="**/lib/*.*"/>
<exclude name="**/classes/**/*.*"/>
<exclude name="**/web.xml"/>
</fileset>
<lib dir="${lib.dir}"/>
<classes dir="${build.dest.web}"/>
</war>
</target>
<target name="clean">
<delete dir="${build.dir}"/>
<delete dir="${distribution.dir}"/>
<mkdir dir="${build.dir}"/>
</target>
</project>
答案 0 :(得分:0)
出于某种原因,当我尝试从Eclipse创建表时,Eclipse会执行classes文件夹中的类。这就是为什么程序认为我想要映射的类是classes / com ...而不是com / ...如果我将build.dest和build.dest.web更改为{build.dir}它的工作原理完美。