Issues with run-time compilation and weaving

49 views
Skip to first unread message

sriv...@hedviginc.com

unread,
May 4, 2016, 6:23:06 PM5/4/16
to kilimthreads
Hi, 

I am trying to do a run-time compilation, weaving and invocation of java source code, but have some issues with the same. Scenario:

I have an existing JVM, which is running an application. I am trying to inject a new class into this existing JVM and perform some operations at runtime. 

For Eg:

String sourceCode= 
"package test;
//necessary imports

Class A extends kilim.Task
{
   public execute() throws Pausable  {
      //Implementation
   }
}"

List<ClassInfo> classInfo = Javac.compile(sourceCode); //I am using the kilim tools javac compiler

URLClassLoader classLoader = URLClassLoader.newInstance(classUrls); //constructing the classURLs as a list of the urls of jars of the JVM and the location of the current .class

Weaver weaver = new Weaver(clsLoader);

List<ClassInfo> weavedClassInfo = weaver.weave(classInfo); //The output of weaving is just one class which was passed as input. However, the bytes are modified

Class<?> cls = (Class<?>) Class.forName(weavedClassInfo.className, true, classLoader);


Task task = (Task)cls.newInstance();

Scheduler s = new Scheduler(1);

task.setScheduler(s);

task.start();  



I am invoking the start method of the Task class by the above steps. 

With the above steps, I get an error message:

"Task C has either not been woven or the classpath is incorrect"

Since weaving has modifid my classBytes, is my classpath incorrect? Any ideas on how do I go about fixing it?


Thanks!




 

Reply all
Reply to author
Forward
0 new messages