Ask a Question

I have external jar file which is placed in /bin/ext of ready api folder. I want to create an object

swetha1
New Contributor

I have external jar file which is placed in /bin/ext of ready api folder. I want to create an object

I have external jar file which is placed in /bin/ext of ready api folder. I want to create an object for a class which is present in the jar. So i am writing an groovy script inside ready api with an import statement. I wrote the import statement like import com.philips.audit.client.threadcontext.AuditThreadContextManager. Here AuditThreadContextManager is the name of my class. This works fine. But since this is like a static import , i will have to write multiple import statements for different classes. Hence i tried giving import com.philips.* . But this not working. ready api 2.2.0 is unable to dynamically import. Can you please help ?

---------------------------------

import com.philips.audit.client.threadcontext.AuditThreadContextManager
AuditThreadContextManager auditThreadContextManager = new AuditThreadContextManager();

 

works fine without any error 

------------------------------------------

import com.philips.*
AuditThreadContextManager auditThreadContextManager = new AuditThreadContextManager();

gives the below error

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script10.groovy: 16: unable to resolve class AuditThreadContextManager @ line 16, column 27. AuditThreadContextManager auditThreadContextManager = new AuditThreadContextManager(); ^ org.codehaus.groovy.syntax.SyntaxException: unable to resolve class AuditThreadContextManager @ line 16, column 27. at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:149) at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:264) at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:274) at org.codehaus.groovy.control.ResolveVisitor.transformVariableExpression(ResolveVisitor.java:944) at org.codehaus.groovy.control.ResolveVisitor.transform(ResolveVisitor.java:696) at org.codehaus.groovy.control.ResolveVisitor.transformDeclarationExpression(ResolveVisitor.java:1083) at org.codehaus.groovy.control.ResolveVisitor.transform(ResolveVisitor.java:700) at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitExpressionStatement(ClassCodeExpressionTransformer.java:142) at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:42) at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:37) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:166) at org.codehaus.groovy.control.ResolveVisitor.visitBlockStatement(ResolveVisitor.java:1320) at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:71) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:104) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:115) at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitConstructorOrMethod(ClassCodeExpressionTransformer.java:53) at org.codehaus.groovy.control.ResolveVisitor.visitConstructorOrMethod(ResolveVisitor.java:203) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:126) at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1086) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:53) at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1263) at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:178) at org.codehaus.groovy.control.CompilationUnit$11.call(CompilationUnit.java:651) at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:931) at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:593) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:542) at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298) at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268) at groovy.lang.GroovyShell.parseClass(GroovyShell.java:694) at groovy.lang.GroovyShell.parse(GroovyShell.java:706) at groovy.lang.GroovyShell.parse(GroovyShell.java:742) at groovy.lang.GroovyShell.parse(GroovyShell.java:733) at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.recompileWithNewName(SoapUIGroovyScriptEngine.java:155) at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.compile(SoapUIGroovyScriptEngine.java:146) at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:95) at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SoapUIProGroovyScriptEngineFactory.java:82) at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:156) at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Script10.groovy: 16: unable to resolve class AuditThreadContextManager @ line 16, column 55. r auditThreadContextManager = new AuditT ^ org.codehaus.groovy.syntax.SyntaxException: unable to resolve class AuditThreadContextManager @ line 16, column 55. at org.codehaus.groovy.ast.ClassCodeVisitorSupport.addError(ClassCodeVisitorSupport.java:149) at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:264) at org.codehaus.groovy.control.ResolveVisitor.resolveOrFail(ResolveVisitor.java:274) at org.codehaus.groovy.control.ResolveVisitor.transformConstructorCallExpression(ResolveVisitor.java:1049) at org.codehaus.groovy.control.ResolveVisitor.transform(ResolveVisitor.java:708) at org.codehaus.groovy.control.ResolveVisitor.transformDeclarationExpression(ResolveVisitor.java:1090) at org.codehaus.groovy.control.ResolveVisitor.transform(ResolveVisitor.java:700) at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitExpressionStatement(ClassCodeExpressionTransformer.java:142) at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:42) at org.codehaus.groovy.ast.CodeVisitorSupport.visitBlockStatement(CodeVisitorSupport.java:37) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitBlockStatement(ClassCodeVisitorSupport.java:166) at org.codehaus.groovy.control.ResolveVisitor.visitBlockStatement(ResolveVisitor.java:1320) at org.codehaus.groovy.ast.stmt.BlockStatement.visit(BlockStatement.java:71) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClassCodeContainer(ClassCodeVisitorSupport.java:104) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitConstructorOrMethod(ClassCodeVisitorSupport.java:115) at org.codehaus.groovy.ast.ClassCodeExpressionTransformer.visitConstructorOrMethod(ClassCodeExpressionTransformer.java:53) at org.codehaus.groovy.control.ResolveVisitor.visitConstructorOrMethod(ResolveVisitor.java:203) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitMethod(ClassCodeVisitorSupport.java:126) at org.codehaus.groovy.ast.ClassNode.visitContents(ClassNode.java:1086) at org.codehaus.groovy.ast.ClassCodeVisitorSupport.visitClass(ClassCodeVisitorSupport.java:53) at org.codehaus.groovy.control.ResolveVisitor.visitClass(ResolveVisitor.java:1263) at org.codehaus.groovy.control.ResolveVisitor.startResolving(ResolveVisitor.java:178) at org.codehaus.groovy.control.CompilationUnit$11.call(CompilationUnit.java:651) at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:931) at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:593) at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:542) at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298) at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268) at groovy.lang.GroovyShell.parseClass(GroovyShell.java:694) at groovy.lang.GroovyShell.parse(GroovyShell.java:706) at groovy.lang.GroovyShell.parse(GroovyShell.java:742) at groovy.lang.GroovyShell.parse(GroovyShell.java:733) at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.recompileWithNewName(SoapUIGroovyScriptEngine.java:155) at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.compile(SoapUIGroovyScriptEngine.java:146) at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:95) at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SoapUIProGroovyScriptEngineFactory.java:82) at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:156) at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) 2 errors

4 REPLIES 4
JHunt
Community Hero

You can only import one package at a time with the star import. So this should work:

 

import com.philips.audit.client.threadcontext.*

But you'll need at least one for every package you reference classes in. That's normal for Java and for Groovy, and it's not unusual to see a dozen imports or so at the top of a source file.

 

I can see how that might be a little annoying when you have to write out all the imports manually in ReadyAPI. When using other IDEs it's hardly a problem at all - you just try to reference that class, it complains that you haven't imported it and offers to add the import for you.

swetha1
New Contributor

Thanks for your response. It is valuable. But my AuditThreadContextManager class has many other imports statements in it. So does it mean i have to import all of those manually in ready api ? That could be a tidious job!

swetha1
New Contributor

Thanks for your response. It is valuable. But my AuditThreadContextManager class has many other imports statements in it. So does it mean i have to import all of those manually in ready api ? That could be a tidious job!

JHunt
Community Hero

No. When you import a class, you automatically import all the things that it imports.

cancel
Showing results for 
Search instead for 
Did you mean: