我使用Ant 1.9.1构建了jar存档当我从它启动类时,我得到以下异常:
Caused by Java exception: java.lang.NoSuchMethodError: com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput.setChecked(Z)V
at com.blablabla.kats.drivers.CheckBox.check(CheckBox.java:57)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.blablabla.kats.utils.Operation.doInvoke(Operation.java:142)
at com.blablabla.kats.utils.Operation.invokeMethod(Operation.java:117)
at com.blablabla.kats.model.handles.ElementOperationHandle.invokeOn(ElementOperationHandle.java:33)
at com.blablabla.kats.model.statements.DirectAction.execute(DirectAction.java:45)
at com.blablabla.kats.model.StatementSequence.executeStatement(StatementSequence.java:74)
at com.blablabla.kats.model.StatementSequence.doExecute(StatementSequence.java:50)
at com.blablabla.kats.model.Procedure.call(Procedure.java:46)
at com.blablabla.kats.model.statements.Invocation.execute(Invocation.java:48)
at com.blablabla.kats.model.StatementSequence.executeStatement(StatementSequence.java:74)
at com.blablabla.kats.model.StatementSequence.doExecute(StatementSequence.java:50)
at com.blablabla.kats.model.TestCase.execute(TestCase.java:41)
at com.blablabla.kats.model.TestSuite.execute(TestSuite.java:45)
at com.blablabla.kats.model.TestProgram.execute(TestProgram.java:40)
at com.blablabla.kats.Main.main(Main.java:158)
当我编译"com.blablabla.kats.drivers. "用javac的CheckBox类替换相应的jar文件都可以正常工作。我使用htmlunit 2.12
java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
对应的Ant任务:
<path id="classpath.libraries">
<fileset dir="${basedir}/lib">
<include name="*.jar"/>
</fileset>
</path>
<target name="compile">
<javac srcdir="${basedir}/src/java" destdir="classes" debug="true" source="1.5" target="1.5">
<classpath refid="classpath.libraries" />
</javac>
</target>
${basedir}/lib包含大量的jar文件。
主要有kats.jar -我的项目,包含com.blablabla.kats.drivers.CheckBox
htmlunit-2.12.jar -其中com. gargoylesofware .htmlunit.html. htmlcheckboxinput . setchecked (Z)
为什么会发生?
我看到的唯一区别是,您在ant脚本中使用1.5,其中查看java版本,您使用java6来运行它。我不确定这是否会有很大的不同,因为它应该是向后兼容的,但仍然给它一个尝试。在ant build.xml
我发现我没有删除旧的编译类。当我清理编译后的类,所有的工作都很好。