2015-08-24 87 views
1
> BUILD FAILED 
> C:\Users\dt208672\Perforce\depot\ebill\Automation\Selenium_eBill\RunningPower\build.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構建我的應用程序時發生的錯誤。似乎錯誤與類路徑有關。我的程序能夠編譯但不能運行。我被告知解決這個問題的方法是在運行時包含類路徑,但問題仍然存在。也許我寫的是不正確的?不知道使用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> 

回答

3

運行的jar文件(<java jar="...")時,您不能指定<classpath>

報價java doc

當您使用-jar選項,指定的JAR文件是所有用戶類的源,和其他類路徑設置將被忽略。

+0

是否有另一種類路徑標記的替代方案,我可以使用這樣的jar文件可以知道它在運行時看的地方? – LinhSaysHi

+0

jar文件中的清單必須指定類路徑。 – Andreas

+0

'classpath'元素不應該導致OP提到的錯誤(即使這裏不需要)。 – manouti

相關問題