gpt4 book ai didi

java - 运行 build.xml 文件时出错

转载 作者:行者123 更新时间:2023-12-01 13:06:13 25 4
gpt4 key购买 nike

我是 ANT 构建的新手,在尝试运行下面提到的构建文件时遇到一些错误。我已将所有 jar 文件添加到 lib 文件夹中。但我仍然面临这些错误。我想我在类路径区域犯了一些其他错误。

这是 build.xml

<project name="ant_testing" default="compile" basedir=".">

<property name="jar" value="${basedir}/classes"/>
<property name="lib" value="${basedir}/lib"/>
<property name="src" value="${basedir}/src"/>
<property name="classes" value="${basedir}/classes"/>

<target name="setClassPath" unless="test.classpath">
<path id="testcompile">
<pathelement location="${jar}"/>
<fileset dir="${lib}">
<include name="*.jar"/>
</fileset>
</path>
</target>

<target name="compile" depends="setClassPath">
<javac includeantruntime="false" srcdir="${src}" destdir="${classes}" includes="**/*.java" listfiles="yes"/>
<classpath refid="testcompile"/>
</target>

<target name="run" depends="compile">
<java>
<classpath path="classes"/>
</java>
</target>

</project>

这是错误列表

Buildfile: D:\sakthi\JUNIT\ant_testing\build.xml
setClassPath:
compile:
[javac] Compiling 1 source file to D:\sakthi\JUNIT\ant_testing\classes
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:3: error: package org.testng.annotations does not exist
[javac] import org.testng.annotations.BeforeClass;
[javac] ^
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:4: error: package org.testng.annotations does not exist
[javac] import org.testng.annotations.BeforeSuite;
[javac] ^
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:5: error: package org.testng.annotations does not exist
[javac] import org.testng.annotations.BeforeTest;
[javac] ^
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:6: error: package org.testng.annotations does not exist
[javac] import org.testng.annotations.DataProvider;
[javac] ^
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:7: error: package org.testng.annotations does not exist
[javac] import org.testng.annotations.Test;
[javac] ^
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:8: error: package com.thoughtworks.selenium does not exist
[javac] import com.thoughtworks.selenium.SeleneseTestBase;
[javac] ^
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:12: error: package jxl does not exist
[javac] import jxl.*;
[javac] ^
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:14: error: cannot find symbol
[javac] public class ant_testing extends SeleneseTestBase{
[javac] ^
[javac] symbol: class SeleneseTestBase
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:18: error: cannot find symbol
[javac] @BeforeSuite
[javac] ^
[javac] symbol: class BeforeSuite
[javac] location: class ant_testing
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:29: error: cannot find symbol
[javac] @BeforeTest
[javac] ^
[javac] symbol: class BeforeTest
[javac] location: class ant_testing
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:45: error: cannot find symbol
[javac] @DataProvider(name = "DP1")
[javac] ^
[javac] symbol: class DataProvider
[javac] location: class ant_testing
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:53: error: cannot find symbol
[javac] @Test (dataProvider = "DP1")
[javac] ^
[javac] symbol: class Test
[javac] location: class ant_testing
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:74: error: cannot find symbol
[javac] Workbook workbook = Workbook.getWorkbook(new File(xlFilePath));
[javac] ^
[javac] symbol: class Workbook
[javac] location: class ant_testing
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:74: error: cannot find symbol
[javac] Workbook workbook = Workbook.getWorkbook(new File(xlFilePath));
[javac] ^
[javac] symbol: variable Workbook
[javac] location: class ant_testing
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:75: error: cannot find symbol
[javac] Sheet sheet = workbook.getSheet(sheetName);
[javac] ^
[javac] symbol: class Sheet
[javac] location: class ant_testing
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:77: error: cannot find symbol
[javac] Cell tableStart=sheet.findCell(tableName);
[javac] ^
[javac] symbol: class Cell
[javac] location: class ant_testing
[javac] D:\sakthi\JUNIT\ant_testing\src\comm\code\ant_testing.java:80: error: cannot find symbol
[javac] Cell tableEnd= sheet.findCell(tableName, startCol+1,startRow+1, 100, 64000, false);
[javac] ^
[javac] symbol: class Cell
[javac] location: class ant_testing
[javac] 17 errors

BUILD FAILED
D:\sakthi\JUNIT\ant_testing\build.xml:19: Compile failed; see the compiler error output for details.
Total time: 611 milliseconds

帮我解决这个问题:(。预先感谢:)

最佳答案

您的编译在其类路径中没有 jar。以下是声明 javac 任务的方式:

<javac includeantruntime="false" srcdir="${src}" destdir="${classes}" includes="**/*.java" listfiles="yes"/>

尝试以下简化的构建文件:

<project name="ant_testing" default="compile" basedir=".">

<property name="build.dir" location="build"/>
<property name="lib.dir" location="lib"/>
<property name="src.dir" location="src"/>
<property name="classes.dir" location="${build.dir}/classes"/>

<path id="compile.path">
<fileset dir="${lib.dir}" includes="*.jar"/>
</path>

<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="compile.path" includeantruntime="false"/>
</target>

<target name="run" depends="compile">
<java .. ..>
<classpath>
<path refid="compile.path"/>
<pathelement location="${classes.dir}"/>
</classpath>
</java>
</target>
</project>

注释:

  • 编译在顶部声明的类路径以及属性等其他项目
  • 属性使用“位置”属性。专为文件路径名而设计
  • Javac 任务使用 classpathref 接受其类路径
  • Java 任务有一个类路径元素,由现有路径和目录文件路径元素组成。

关于java - 运行 build.xml 文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23245625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com