I am new to Groovy and working with another product called SoapUI. SoapUI uses Groovy to execute java code. I created an executable JAR file that I understood could be executed within a Groovy Script. Per another forum, I found that I should be able to execute a jar via groovy using this groovy code:
package groovyPackage
class RevisedGroovyScript {
def command = "java -jar UpdateAppIdXMLRequest.jar file.xml";
def process = command.execute()
process.waitFor()
def output = process.in.text
log.info output
}
However, when I try to execute this groovy code within Eclipse, I get a few errors:
Groovy:The field 'process' is declared multiple times.
Groovy:unexpected token: process @ line 7, column 2.
Groovy:unexpected token: log @ line 10, column 2.
Any help/direction would be appreciated. Thanks.
|
|
|
|
|
Melinda Savoy |
||
|
Sr. Developer |
||
|
Privileged and Confidential. This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain privileged and/or confidential information. If you have received this e-mail in error, please notify me immediately by a return e-mail and delete this e-mail. You are hereby notified that any dissemination, distribution or copying of this e-mail and/or any attachments thereto, is strictly prohibited. |
Thanks for the reply.
One more question if you don’t mind. In my jar I have the following simple Java code:
public static void main(String[] args) {
try {
String xmlFileArg = args[0];
if (xmlFileArg == null || xmlFileArg.isEmpty()) {
return;
}
SAXBuilder builder = new SAXBuilder();
File xmlFile = new File(xmlFileArg);
Document doc = (Document) builder.build(xmlFile);
Element rootNode = doc.getRootElement();
// Loop to create 25 testStepApps
for (int i = 1; i < 26; i++) {
// increment and then update the ApplicationNumber attribute value
int appID = Integer.parseInt(rootNode.getAttributeValue("ApplicationNumber"));
appID++;
String appIDValue = Integer.toString(appID);
rootNode.getAttribute("ApplicationNumber").setValue(appIDValue);
XMLOutputter xmlOutput = new XMLOutputter();
// Create new XML file with next AppID
xmlOutput.setFormat(Format.getPrettyFormat());
xmlOutput.output(doc, new FileWriter("testStepApp" + i + ".xml"));
// xmlOutput.output(doc, System.out);
// System.out.println("File updated!");
}
} catch (IOException io) {
io.printStackTrace();
} catch (JDOMException e) {
e.printStackTrace();
}
}
My question is how do I define in my java code WHERE the created testSteps should be created in SoapUI so that they are created within my SoapUI project? Hope that makes sense.
Thanks again.
|
|
|
|
|
Melinda Savoy |
||
|
Sr. Developer |
||
|
Privileged and Confidential. This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain privileged and/or confidential information. If you have received this e-mail in error, please notify me immediately by a return e-mail and delete this e-mail. You are hereby notified that any dissemination, distribution or copying of this e-mail and/or any attachments thereto, is strictly prohibited. |
From: ysb33r [via Groovy] [mailto:ml-node+[hidden email]]
Sent: Tuesday, September 02, 2014 7:56 AM
To: Melinda Savoy
Subject: Re: Question about executing JAR file within groovy script
If you drop the JAR within the SoapUI lib area, it does not need to be executable and your Groovy code should be able to find the classes you import.
On 02/09/2014 13:49, Melinda Savoy wrote:
I am new to Groovy and working with another product called SoapUI. SoapUI uses Groovy to execute java code. I created an executable JAR file that I understood could be executed within a Groovy Script. Per another forum, I found that I should be able to execute a jar via groovy using this groovy code:
package groovyPackage
class RevisedGroovyScript {
def command = "java -jar UpdateAppIdXMLRequest.jar file.xml";
def process = command.execute()
process.waitFor()
def output = process.in.text
log.info output
}
However, when I try to execute this groovy code within Eclipse, I get a few errors:
Groovy:The field 'process' is declared multiple times.
Groovy:unexpected token: process @ line 7, column 2.
Groovy:unexpected token: log @ line 10, column 2.
Any help/direction would be appreciated. Thanks.
Melinda Savoy
Sr. Developer
P: | Elevate.com
4150 International Plaza, Suite 300
Fort Worth, TX 76109
Privileged and Confidential. This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain privileged and/or confidential information. If you have received this e-mail in error, please notify me immediately by a return e-mail and delete this e-mail. You are hereby notified that any dissemination, distribution or copying of this e-mail and/or any attachments thereto, is strictly prohibited.
--
Schalk W. Cronjé
@ysb33r
If you reply to this email, your message will be added to the discussion below:
To unsubscribe from Question about executing JAR file within groovy script,
click here.
NAML
Thanks, Marc. I appreciate your help. I tried posting to the soapui forum but never got a response. Consequently I was not sure if I could execute a JAR file from within a groovy script or not. I appreciate everyone’s help.
Thanks again.
|
|
|
|
|
Melinda Savoy |
||
|
Sr. Developer |
||
|
Privileged and Confidential. This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain privileged and/or confidential information. If you have received this e-mail in error, please notify me immediately by a return e-mail and delete this e-mail. You are hereby notified that any dissemination, distribution or copying of this e-mail and/or any attachments thereto, is strictly prohibited. |
From: Marc Paquette [via Groovy] [mailto:ml-node+[hidden email]]
Sent: Tuesday, September 02, 2014 8:38 AM
To: Melinda Savoy
Subject: Re: Question about executing JAR file within groovy script
This question is more for forums.soapui.org than this mailing list. However, if I interpreted your question correctly, your are trying to add steps to your projects programatically from inside a groovy script running as a step in your project by calling java code in a jar file.
First, it is preferred to put the jar files you create as "extensions" to soapui run-time into the SOAPUI_HOME/bin/ext folder : it will be picked up by soapui at startup and you can clearly see what is provided by the plateform and what you added.
Second, from the groovy script, you can call methods on the objects you have and those you can reach. From the 'testRunner' variable, you can get to the test case with 'testRunner.testCase' from which you can get to the suite with 'testRunner.testCase.testSuite' from which you can get to the project with 'testRunner.testCase.testSuite.project'. Read the javadoc on soapui.org to see what you can do. The point is that you can call these documented methods directly from a "groovy script test step", you don't necessarily have to "call" a jar coded in java to do it.
Furthermore, from your groovy script test step, you can call methods on java object or groovy objects or both, provided that they are in soapui's groovy script engine classpath (and that you import them in the script). Java byte code is what gets executed, so it does not matter if your jar contains classes coded in java or groovy. For instance, you can use groovy's XMLParser or XMLSluper in a script.
HTH,
Marc Paquette
|
|
|
|
|
Melinda Savoy |
|
|
Sr. Developer |
|
Privileged and Confidential. This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain privileged and/or confidential information. If you have received this e-mail in error, please notify me immediately by a return e-mail and delete this e-mail. You are hereby notified that any dissemination, distribution or copying of this e-mail and/or any attachments thereto, is strictly prohibited. |
From: ysb33r [via Groovy] [mailto:ml-node+<a
href="x-msg://2/user/SendEmail.jtp?type=node&node=5721109&i=0" target="_top" rel="nofollow" link="external">[hidden email]]
Sent: Tuesday, September 02, 2014 7:56 AM
To: Melinda Savoy
Subject: Re: Question about executing JAR file within groovy script
If you drop the JAR within the SoapUI lib area, it does not need to be executable and your Groovy code should be able to find the classes you import.
On 02/09/2014 13:49, Melinda Savoy wrote:
I am new to Groovy and working with another product called SoapUI. SoapUI uses Groovy to execute java code. I created an executable JAR file that I understood could be executed within a Groovy Script. Per another forum, I found that I should be able to execute a jar via groovy using this groovy code:
package groovyPackage
class RevisedGroovyScript {
def command = "java -jar UpdateAppIdXMLRequest.jar file.xml";
def process = command.execute()
process.waitFor()
def output = process.in.text
log.info output
}
However, when I try to execute this groovy code within Eclipse, I get a few errors:
Groovy:The field 'process' is declared multiple times.
Groovy:unexpected token: process @ line 7, column 2.
Groovy:unexpected token: log @ line 10, column 2.
Any help/direction would be appreciated. Thanks.
Melinda Savoy
Sr. Developer
P: | Elevate.com
4150 International Plaza, Suite 300
Fort Worth, TX 76109
Privileged and Confidential. This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain privileged and/or confidential information. If you have received this e-mail in error, please notify me immediately by a return e-mail and delete this e-mail. You are hereby notified that any dissemination, distribution or copying of this e-mail and/or any attachments thereto, is strictly prohibited.
--
Schalk W. Cronjé
@ysb33r
If you reply to this email, your message will be added to the discussion below:
To unsubscribe from Question about executing JAR file within groovy script,
click here.
NAML
View this message in context:
RE: Question about executing JAR file within groovy script
Sent from the
groovy - user mailing list archive at
Nabble.com.
If you reply to this email, your message will be added to the discussion below:
To unsubscribe from Question about executing JAR file within groovy script,
click here.
NAML