Issues with run-time compilation and weaving

Skip to first unread message

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

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  {

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);



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?



Reply all
Reply to author
0 new messages