如何使用 Ant 将整个 lib 目录(包括所有子目录)放在类路径上?
我不确定这就是问题所在,但看起来可能是这样。我收到构建错误,告诉我某些包不存在。这些包是存在于我的 lib 目录中的 .jar 文件中的包。我正在编译并复制到类目录的 java 源文件中的任何其他包都工作正常。以下是与此问题相关的 Ant 构建脚本的一些基础知识:
<property name="app.name" value="myapp" />
<property name="base.dir" value="${basedir}" />
<property name="build.dir" value="${base.dir}/build" />
<property name="build.webinf.dir" value="${build.dir}/WEB-INF" />
<property name="build.classes.dir" value="${build.webinf.dir}/classes" />
<property name="build.lib.dir" value="${build.webinf.dir}/lib" />
<property name="catalina.dir" value="C:\Program Files\Apache Software Foundation\apache-tomcat-5.5.28" />
<property name="catalina.lib.dir" value="${catalina.dir}/shared/lib" />
<property name="config.dir" value="${base.dir}/config" />
<property name="dist.dir" value="${basedir}/dist"/>
<property name="lib.dir" value="${base.dir}/lib" />
<property name="src.dir" value="${base.dir}/src" />
<property name="www.dir" value="${base.dir}/www" />
<path id="compile.classpath">
<fileset dir="${lib.dir}">
<include name="*.jar" />
</fileset>
<pathelement location="${catalina.dir}/common/classes" />
<fileset dir="${catalina.dir}/common/endorsed">
<include name="*.jar" />
</fileset>
<fileset dir="${catalina.dir}/common/lib">
<include name="*.jar" />
</fileset>
<pathelement location="${catalina.dir}/shared/classes"/>
<fileset dir="${catalina.lib.dir}">
<include name="*.jar" />
</fileset>
</path>
<target name="init">
<mkdir dir="${build.dir}" />
<mkdir dir="${build.webinf.dir}" />
<mkdir dir="${build.classes.dir}" />
<mkdir dir="${build.lib.dir}" />
<mkdir dir="${dist.dir}" />
<mkdir dir="${src.dir}" />
</target>
<target name="prepare_www_dir" description="Copies all static web content onto the build path.">
<copy todir="${build.dir}">
<fileset dir="${www.dir}"/>
</copy>
</target>
<target name="prepare_lib_dir" description="Copies all libraries onto the build lib path.">
<copy todir="${build.lib.dir}">
<fileset dir="${lib.dir}" includes="**/*.jar" />
</copy>
</target>
<target name="compile" depends="init,prepare_www_dir,prepare_lib_dir" description="Compiles source code, and copies it onto the build class path.">
<javac srcdir="${src.dir}" destdir="${build.classes.dir}">
<classpath refid="compile.classpath" />
</javac>
</target>
I'm not sure this is the problem, but it looks like it might be the case. I'm getting build errors telling me that certain packages don't exist. These packages are packages that exist in .jar files within my lib directory. Any other packages within my java source files that I'm compiling and copying to the classes directory are working just fine. Here are some of the basics of my Ant build script related to this issue:
<property name="app.name" value="myapp" />
<property name="base.dir" value="${basedir}" />
<property name="build.dir" value="${base.dir}/build" />
<property name="build.webinf.dir" value="${build.dir}/WEB-INF" />
<property name="build.classes.dir" value="${build.webinf.dir}/classes" />
<property name="build.lib.dir" value="${build.webinf.dir}/lib" />
<property name="catalina.dir" value="C:\Program Files\Apache Software Foundation\apache-tomcat-5.5.28" />
<property name="catalina.lib.dir" value="${catalina.dir}/shared/lib" />
<property name="config.dir" value="${base.dir}/config" />
<property name="dist.dir" value="${basedir}/dist"/>
<property name="lib.dir" value="${base.dir}/lib" />
<property name="src.dir" value="${base.dir}/src" />
<property name="www.dir" value="${base.dir}/www" />
<path id="compile.classpath">
<fileset dir="${lib.dir}">
<include name="*.jar" />
</fileset>
<pathelement location="${catalina.dir}/common/classes" />
<fileset dir="${catalina.dir}/common/endorsed">
<include name="*.jar" />
</fileset>
<fileset dir="${catalina.dir}/common/lib">
<include name="*.jar" />
</fileset>
<pathelement location="${catalina.dir}/shared/classes"/>
<fileset dir="${catalina.lib.dir}">
<include name="*.jar" />
</fileset>
</path>
<target name="init">
<mkdir dir="${build.dir}" />
<mkdir dir="${build.webinf.dir}" />
<mkdir dir="${build.classes.dir}" />
<mkdir dir="${build.lib.dir}" />
<mkdir dir="${dist.dir}" />
<mkdir dir="${src.dir}" />
</target>
<target name="prepare_www_dir" description="Copies all static web content onto the build path.">
<copy todir="${build.dir}">
<fileset dir="${www.dir}"/>
</copy>
</target>
<target name="prepare_lib_dir" description="Copies all libraries onto the build lib path.">
<copy todir="${build.lib.dir}">
<fileset dir="${lib.dir}" includes="**/*.jar" />
</copy>
</target>
<target name="compile" depends="init,prepare_www_dir,prepare_lib_dir" description="Compiles source code, and copies it onto the build class path.">
<javac srcdir="${src.dir}" destdir="${build.classes.dir}">
<classpath refid="compile.classpath" />
</javac>
</target>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)