users@glassfish.java.net

Re: Loading Classes in at Runtime - NoClassDefFound

From: <glassfish_at_javadesktop.org>
Date: Tue, 02 Dec 2008 09:51:15 PST

I don't override it, I just call it from my own loadProblems() method inside. I can't think of any other way than to use the defineClass() method... this is what I do...

-> Create a new File object (user-specified directory, or a directory specified by a constant - eg, "C:/Projects/MyProject/classes")
-> Iterate over all directories and files underneath this directory, until I have all class file paths, eg: "C:/Projects/MyProject/classes/WireAreaProblem.class", "C:/Projects/MyProject/classes/problems/RoyalRoadProblem.class", etc.
-> Iterate over all these paths, and for each, turn them into a byte array, and use this to get a corresponding Class object using defineClass(String, byte[], int, int).
-> For each class object, check if they implement my ProblemInterface and filther them accordingly.

It's my hope that new classes can simply be added to a directory on the server, and when the next user calls "getClasses()", he'll get an up-to-date list of what's there.

Maybe my approach is way off? I know it works fairly perfect on my client-side application... I just hoped it would required little or no adaption to work on my server.

Cheers
[Message sent by forum member 'calmdownmonkey' (calmdownmonkey)]

http://forums.java.net/jive/thread.jspa?messageID=319610