java 在 groovy 脚本 (soapui) 中导入 jar 时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10362941/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 00:42:23  来源:igfitidea点击:

Error importing jar in groovy script (soapui)

javagroovysoapui

提问by Oleksandr Martynov

I have a problem with running java code from groovy script (groovy script is a part of SoapUI test suite) i create simple script:

我在从 groovy 脚本运行 java 代码时遇到问题(groovy 脚本是 SoapUI 测试套件的一部分)我创建了简单的脚本:

import myjar.jar
new TopClass().sayHello()

the code of TopClass:

TopClass的代码:

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

I put myjar.jar into both soapui-pro-2.5\lib and soapui-pro-2.5\bin\ext folders. But running script I get:

我将 myjar.jar 放入soapui-pro-2.5\lib 和soapui-pro-2.5\bin\ext 文件夹中。但是运行脚本我得到:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, Script1.groovy: 2: unable to resolve class myjar.jar @ line 2, column 1.org.codehaus.groovy.syntax.SyntaxException: unable to resolve class myjar.jar @ line 2, column 1. at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:113) at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:970) at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:141) at org.codehaus.groovy.control.CompilationUnit$5.call(CompilationUnit.java:527) at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:772) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:438) at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:281) at groovy.lang.GroovyShell.parseClass(GroovyShell.java:572) at groovy.lang.GroovyShell.parse(GroovyShell.java:584) at groovy.lang.GroovyShell.parse(GroovyShell.java:564) at groovy.lang.GroovyShell.parse(GroovyShell.java:603) at

org.codehaus.groovy.control.MultipleCompilationErrorsException:启动失败,Script1.groovy:2:无法解析类 myjar.jar @第 2 行,第 1.org.codehaus.groovy.syntax.SyntaxException:无法解析类 myjar.jar @ 第 2 行,第 1 列。在 org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:113) 在 org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:970) 在 org.codehaus。 groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:141) at org.codehaus.groovy.control.CompilationUnit$5.call(CompilationUnit.java:527) at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java) :772) 在 org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:438) 在 groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:281) at groovy.lang.GroovyShell.parseClass(GroovyShell.java:572) at groovy.lang.GroovyShell.parse(GroovyShell.java:584) at groovy.lang.GroovyShell.parse(GroovyShell.java:564) groovy.lang.GroovyShell.parse(GroovyShell.java:603) 在

Please help me to find what I'm doing wrong

请帮我找出我做错了什么

采纳答案by RonK

Putting the jar under soapui-pro-2.5\bin\extis all you need for the classes to be found (although restarting SoapUIwon't hurt).

将 jar 放在下面soapui-pro-2.5\bin\ext是找到类所需的全部内容(尽管重新启动SoapUI不会有什么坏处)。

However - you should check that the error you get is related to your jar. Is com.my.researchavailable within myjar.jar? If no - just add it.

但是 - 您应该检查您得到的错误是否与您的 jar 相关。是com.my.research内可用myjar.jar?如果没有 - 只需添加它。

If yes, add more detailed information to your post.

如果是,请在您的帖子中添加更多详细信息。

回答by Philippe

import myjar.jar

导入 myjar.jar

I believe this is not correct, you should be importing the name of the java package not the name of the jar. Hope this helps

我相信这是不正确的,您应该导入 java 包的名称而不是 jar 的名称。希望这可以帮助

回答by sweetfa

On non-windows implementations of soapui I find it helps if you add it to the .sh file that starts soapui explicitly.

在soapui 的非Windows 实现上,我发现如果将它添加到显式启动soapui 的.sh 文件中会有所帮助。