我在Eclipse中有一个Web应用程序正常运行。我使用下面的ant脚本构建了一个war文件,它一直有效,直到程序试图访问Hibernate:
<?xml version="1.0" encoding="UTF-8"?>
<!-- !DOCTYPE removes the warning:
No grammar constraints (DTD or XML schema) detected for the document.
-->
<!DOCTYPE project>
<project name="Audiclave" default="Deploy" basedir=".">
<property name="src.dir" location="src" />
<property name="build.dir" location="build" />
<property name="dist.dir" location="dist" />
<property name="build.classes" location="build/classes" />
<property name="docs.dir" location="docs" />
<property name="web.dir" location="WebContent" />
<!-- Deletes the existing build, docs and dist directory-->
<target name="clean">
<delete dir="${build.classes}" />
<delete dir="${build.dir}" />
<delete dir="${docs.dir}" />
<delete dir="${dist.dir}" />
</target>
<!-- Creates the build, docs and dist directory-->
<target name="makedir">
<mkdir dir="${build.classes}" />
<mkdir dir="${build.dir}" />
<mkdir dir="${docs.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<path id="compile.classpath">
<fileset dir="${web.dir}/WEB-INF/lib">
<include name="*.jar" />
</fileset>
</path>
<target name="compile" depends="clean,makedir">
<javac srcdir="${src.dir}" debug="true" destdir="${build.classes}">
<classpath refid="compile.classpath" />
</javac>
</target>
<!-- Creates Javadoc -->
<target name="docs" depends="compile">
<javadoc packagenames="src" sourcepath="${src.dir}" destdir="${docs.dir}">
<!-- Define which files / directory should get included, we include all -->
<fileset dir="${src.dir}">
<include name="**" />
</fileset>
</javadoc>
</target>
<target name="Deploy">
<war destfile="${build.dir}/audiClave.war" webxml="${web.dir}/WEB-INF/web.xml">
<!-- Include the compiled classes from the compile target -->
<classes dir="${build.classes}" />
<!-- Include any configuration files (hibernate) -->
<fileset dir="${src.dir}" includes="**/*.xml" />
<!-- Include any web content -->
<fileset dir="${web.dir}" />
<lib dir="${web.dir}/WEB-INF/lib" />
</war>
</target>
</project>
我遇到的问题是Hibernate配置文件的定位。在我的申请中,他们在:
audiClave\src
但在部署的应用程序中,xml文件位于:
audiClave
虽然我认为他们需要进入:
audiClave\WEB-INF\classes
我如何发表声明:
<fileset dir="${src.dir}" includes="**/*.xml" />
将文件发送到WEB-INF \ classes目录(如果需要的话)。
修改 更改了脚本以包含以下内容并且它正常工作:
<target name="compile" depends="clean,makedir">
<javac srcdir="${src.dir}" debug="true" destdir="${build.classes}">
<classpath refid="compile.classpath" />
</javac>
<copy todir="${build.classes}">
<fileset dir="${src.dir}" includes="**/*.xml,**/*.properties"/>
</copy>
</target>
答案 0 :(得分:3)
让Ant <copy>
将文件导入/ WEB-INF / classes。你是对的 - 这就是他们所属的地方。请务必创建目录路径。