0

我正在尝试从 SoapUI 中的 Groovy 脚本调用 java 类

我的 Java 类

public class LogTest {
    public void sayHello (){
        System.out.println("Hello");
    }   
}

Groovy 脚本

import LogTest;

new LogTest().sayHello()

我将 LogTest.class 放在...SmartBear\SoapUI-4.6.1\bin\ext路径中并重新启动 SoapUI

但我仍然在 SoapUI 中遇到以下错误

:ERROR:org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script5.groovy: 1: unable to resolve class LogTest
 @ line 1, column 1.
   import LogTest;
   ^
org.codehaus.groovy.syntax.SyntaxException: unable to resolve class LogTest
 @ line 1, column 1.
    at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:148)
    at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1240)
    at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:148)
    at org.codehaus.groovy.control.CompilationUnit$8.call(CompilationUnit.java:601)
    at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:839)
    at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:544)
    at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:493)
    at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:306)
    at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:287)
    at groovy.lang.GroovyShell.parseClass(GroovyShell.java:731)
    at groovy.lang.GroovyShell.parse(GroovyShell.java:743)
    at groovy.lang.GroovyShell.parse(GroovyShell.java:770)
    at groovy.lang.GroovyShell.parse(GroovyShell.java:761)
    at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.compile(SoapUIGroovyScriptEngine.java:148)
    at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:93)
    at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:149)
    at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.runTestStep(AbstractTestCaseRunner.java:239)
    at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.runCurrentTestStep(WsdlTestCaseRunner.java:48)
    at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:148)
    at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:43)
    at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.run(AbstractTestRunner.java:135)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

可能的根本原因是什么

干杯

4

2 回答 2

0

你能解决这个问题吗?如果不是,我遇到了同样的情况,这就是我修复它的方法。

我有一个包含以下信息的 jar 文件(HelloWorldTest.jar):

package helloworldtest;

public class HWT {

    public static String Testing() {
        return "Hello World!";
    }

}

请注意,我的文件名和包名不同。确保在导入 Groovy 时使用包名。

我用了:

import helloworldtest.HWT;

log.info HWT.Testing();

结果将是:

Thu Mar 06 16:26:01 PST 2014:INFO:Hello World!
于 2014-03-07T00:26:22.067 回答
0
  1. 构建一个包含您的代码的 jar 文件 (LogTest)

  2. 将该 jar 文件放在 /bin/ext 目录中。

这将允许您从 Groovy 脚本调用您的代码。

于 2013-11-09T06:27:25.663 回答