我为我的测试项目生成了build.xml。当我发出ant主命令时,它给出了错误 -
Jenkins\workspace\\TestProject\src\com\example\testproject\TestProject.java:2: error: package android.test does not exist
[javac] import android.test.AndroidTestCase;
[javac] ^
[javac] C:\Program Files (x86)\Jenkins\workspace\TestMobileBankApp\TestProject\src\com\example\testproject\TestProject.java:6: error: cannot find symbol
[javac] public class TestProject extends AndroidTestCase {
[javac] ^
[javac] symbol: class AndroidTestCase
[javac] [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_05\lib\ct.sym(META-INF/sym/rt.jar/java/lang/Exception.class)]]
[javac] [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_05\lib\ct.sym(META-INF/sym/rt.jar/java/lang/Override.class)]]
[javac] [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_05\lib\ct.sym(META-INF/sym/rt.jar/java/lang/Object.class)]]
[javac] [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_05\lib\ct.sym(META-INF/sym/rt.jar/java/lang/annotation/Annotation.class)]]
[javac] [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_05\lib\ct.sym(META-INF/sym/rt.jar/java/lang/annotation/Target.class)]]
[javac] [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_05\lib\ct.sym(META-INF/sym/rt.jar/java/lang/annotation/ElementType.class)]]
[javac] [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_05\lib\ct.sym(META-INF/sym/rt.jar/java/lang/annotation/Retention.class)]]
[javac] [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_05\lib\ct.sym(META-INF/sym/rt.jar/java/lang/annotation/RetentionPolicy.class)]]
[javac] [checking com.example.testproject.TestProject]
[javac] C:\Program Files (x86)\Jenkins\workspace\TestProject\src\com\example\testproject\TestProject.java:8: error: method does not override or implement a method from a supertype
[javac] @Override
[javac] ^
[javac] [loading ZipFileIndexFileObject[C:\Program Files\Java\jdk1.8.0_05\lib\ct.sym(META-INF/sym/rt.jar/java/lang/Throwable.class)]]
[javac] C:\Program Files (x86)\Jenkins\workspace\TestProject\src\com\example\testproject\TestProject.java:11: error: cannot find symbol
[javac] super.setUp();
[javac] ^
[javac] symbol: variable super
[javac] location: class TestProject
[javac] C:\Program Files (x86)\Jenkins\workspace\TestMobileBankApp\TestProject\src\com\example\testproject\TestProject.java:15: error: cannot find symbol
[javac] assertEquals(true, true);
[javac] ^
[javac] symbol: method assertEquals(boolean,boolean)
[javac] location: class TestProject
[javac] [total 719ms]
[javac] 5 errors
Windows 7和jenkins也会出现同样的错误。 我试过改变我的jdk路径,但它没有用。
答案 0 :(得分:1)
这是jar文件的问题。你需要在编译时在类路径中添加jar文件。这是在javac任务的类路径中添加jar文件的一个例子。
<path id="selenium.classpath">
<fileset dir="${basedir}/selenium">
<include name="*.jar" />
</fileset>
<pathelement location="${bin.dir}" />
</path>
<classpath refid="selenium.classpath" />
</javac>
这里我已将所有必需的jar放在根目录(基本目录)
下的selenium文件夹中答案 1 :(得分:0)
<path id="selenium.classpath">
<fileset dir="${basedir}/selenium">
<include name="*.jar" />
</fileset>
<pathelement location="${bin.dir}" />
</path>
<target name="compile" >
<javac srcdir="${src.dir}" destdir="${bin.dir}" deprecation="false">
<classpath refid="selenium.classpath"/>
</javac>
</target>
这是部分答案。正确的代码