每当我尝试通过ANT 脚本运行我的代码时,我都会收到此错误“错误: com.mongodb 包不存在”。当我在Eclipse中运行我的代码时,它会成功执行,当我通过ANT脚本执行我的代码时,我会收到此错误. 我已经在项目中包含了 mongoDB jar。
错误 - “包 com.mongodb 不存在”
build.xml -
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="src.dir" location="src" />
<property name="build.dir" location="bin" />
<property name="dist.dir" location="dist" />
<property name="docs.dir" location="docs" />
<!-- Deletes the existing build, docs and dist directory -->
<target name="clean">
<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.dir}" />
<mkdir dir="${docs.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<path id="master-classpath">
<pathelement path="./lib/mongo-2.10.1.jar" >
</pathelement>
</path>
<!-- Compiles the java code (including the usage of library for JUnit -->
<target name="compile" depends="clean, makedir">
<javac srcdir="${src.dir}" destdir="${build.dir}" includeantruntime="false">
<classpath refid="master-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>
<!--Creates the deployable jar file -->
<target name="jar" depends="compile">
<jar destfile="${dist.dir}\CsvReaderExample.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="test.Main" />
</manifest>
</jar>
</target>
<target name="main" depends="compile, jar, docs">
<echo>Hello Ankur - Welcome to Apache Ant!</echo>
<description>Main target</description>
</target>