Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Dynamic Class loading of java source(Dynamic Class loading)
Dynamic Class loading of java source [message #668479] Thu, 05 May 2011 19:54 Go to next message
Jamel G. is currently offline Jamel G.Friend
Messages: 12
Registered: April 2011
Junior Member
Hello,

I would like to compile and load dynamically a class from the current java project and then invoke a method.

I have found this article http://mortennobel.files.wordpress.com/2008/07/dynamichallow orld-java.pdf

It only works when the java class is not referencing any other java class. otherwise i got a compile error.

I think the main problem is in the classpath passed to the eclipse compiler:

JavaCompiler javac = new EclipseCompiler();

StandardJavaFileManager sjfm = javac.getStandardFileManager(null, null, null);
SpecialClassLoader cl = new SpecialClassLoader();
SpecialJavaFileManager fileManager = new SpecialJavaFileManager(sjfm, cl);

List<String> options = new ArrayList<String>();

options.addAll(Arrays.asList("-classpath", System.getProperty("java.class.path")));

List compilationUnits = Arrays.asList(new MemorySource(className, halloWorldProgram));

DiagnosticListener dianosticListener = null;
Iterable classes = null;
Writer out = new PrintWriter(System.err);

JavaCompiler.CompilationTask compile = javac.getTask(out, fileManager, dianosticListener, options, classes, compilationUnits);

boolean res = compile.call();
if (res) {
	return cl.findClass(className);
}


Any help will be much appreciated
Re: Dynamic Class loading of java source [message #668809 is a reply to message #668479] Sat, 07 May 2011 17:27 Go to previous messageGo to next message
Jamel G. is currently offline Jamel G.Friend
Messages: 12
Registered: April 2011
Junior Member
Is it the right forum to ask my question ?! Confused

Plz any help any idea
Re: Dynamic Class loading of java source [message #669994 is a reply to message #668809] Thu, 12 May 2011 11:02 Go to previous message
Satyam Kandula is currently offline Satyam KandulaFriend
Messages: 444
Registered: July 2009
Senior Member
Yes, I too think it should be because of the class path problem. Did you try to see if the referred classes are in the class path provided by System.getProperty("java.class.path")?
Previous Topic:Classpath too long for JUnit (maven dependencies)
Next Topic:Custom coloring inside Java string literals
Goto Forum:
  


Current Time: Tue Mar 19 07:33:45 GMT 2024

Powered by FUDForum. Page generated in 0.01919 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top