> BUILD FAILED
> C:Usersdt208672PerforcedepotebillAutomationSelenium_eBillRunningPowerbuild.xml:37:
> Problem: failed to create task or type classpath Cause: The name is
> undefined. Action: Check the spelling. Action: Check that any custom
> tasks/types have been declared. Action: Check that any
> <presetdef>/<macrodef> declarations have taken place.
这是尝试用Apache Ant构建应用程序时的错误。似乎错误与类路径有关。我的程序可以编译,但不能运行。有人告诉我,解决这个问题的方法是在运行时包含类路径,然而,这个问题仍然存在。也许我写的不对?不知道
<?xml version="1.0" ?>
<project name="SeleniumProjectDataDriven" basedir="." default="run">
<target name="init">
<property name="src.dir" value="src" />
<property name="build.dir" value="build" />
<property name="classes.dir" value="${build.dir}/class" />
<property name="lib.dir" value="RunningPowerJars" />
</target>
<target name="clean" depends="init">
<delete dir="build"/>
</target>
<target name="compile" description="Compiles the code" depends="clean" >
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false">
<classpath>
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</classpath>
</javac>
</target>
<target name="jar" description="Packages the code into jar" depends="compile">
<mkdir dir="build/jar"/>
<jar destfile="build/jar/RunningPower.jar" basedir="build/class">
<manifest>
<attribute name="Main-Class" value="RunningPower"/>
</manifest>
</jar>
</target>
<target name="run" description="Run the jar file" depends="jar" >
<java jar="build/jar/RunningPower.jar" fork="true">
<classpath>
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</classpath>
</java>
</target>
在运行jar文件(<java jar="..."
)时不能指定<classpath>
。
引用java doc:
当您使用-jar选项时,指定的JAR文件是所有用户类的源文件,其他类路径设置将被忽略。