NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Java integration with Groovy Script

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
chairao



Joined: 15 Jun 2012
Posts: 2

PostPosted: Mon Jun 18, 2012 9:12 pm    Post subject: Java integration with Groovy Script Reply with quote

I am trying to run the following Groovy Script to perform a sftp. When I run it from the GroovyConsole, it works perfectly, but when I try to run it from my Java app, it returns an error of 'java.lang.NoClassDefFoundError:org/apache/ivy/core/report/ResolveReport'.

I have seen other references to this error on the web, but none seemed to address my problem directly. There seems to be a problem when the
Grab is being performed. My Java app code is as follows:


fileName= "C:\\Users\\cr.BANDL\\NetBeansProjects\\CallGroovy\\src\\scp.groovy";
ClassLoader parent = getClass().getClassLoader();
GroovyClassLoader loader = new GroovyClassLoader(parent);
Class groovyClass = loader.parseClass(new File(fileName));
GroovyObject groovyObject=(GroovyObject) groovyClass.newInstance();
Object[] args = "root@spacely:/usr/chai/char.c", "c:\\temp", "bandl220"};
System.out.println("Invoking groovyobject\n");
groovyObject.invokeMethod("run", args);


The following is my script:

#!/usr/bin/env groovy
import groovy.grape.Grape;
import groovy.lang.Grab;
import groovy.*;

class scpparams {
def run (Object[] args) {
System.out.println('Inside scpparams run method\n')
def pw
def src
def trgt
src = args[0]
trgt = args[1]
pw = args[2]
def source = new String(src)
def target = new String(trgt)
def pwStr = new String(pw);
println 'In scpparams, src:' + source + ', trgt:' + target + ',
password:' + pwStr
Grape.grab(autoDownload:true, group:"ant", module:"ant-jsch",
version:"1.6.5", classLoader:this.class.classLoader.rootLoader)
Grape.grab(autoDownload:true, group:"com.jcraft", module:"jsch",
version:"0.1.42", classLoader:this.class.classLoader.rootLoader)

println('Grape.grab done\n')
def ant = new AntBuilder()
System.out.println('Antbuilder object created\n')
System.out.println('About to start scp\n')
ant.scp(trust:'true',file:source, //file:"root@spacely:/usr/chai/char.c",
todir:target, //"c:\\temp",
password:"${pwStr}",verbose:"true")
}
}
Back to top
chairao



Joined: 15 Jun 2012
Posts: 2

PostPosted: Tue Jun 19, 2012 12:01 pm    Post subject: Reply with quote

Never mind. I ended up using the Jsch jar file as a library and was successful in doing an sftp.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo