• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Java Class Loading

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.
I'm at work today 🙁 - So will get back and give you more details + source code as soon as I can.

Also, I needed to edit an earlier post to read: The plugins are now stored at /plugins (It read 'not' before)

Thanks once more Kamper
 
try tossing this in:

if (obj instanceof PlugIn)

to see if you are getting the expected clas type back (although someone alerady said you are not).

Doing anything with Eclipse or NetBeans? It's the only time I've seen plug-ins used before 🙂 if so, PM me so I can return to the thread and learn more ...
 
Nah mate - BlueJ (www.blueJ.org) 😀

I can't stand the 'professional' IDEs which can't view the object as it is being run (i.e I can pause the process and view the current contents of an ArrayList or Vector). Unless that feature exists in them but I cant find it....

whoooooo, 50mins left of work.
 
Originally posted by: IHateMyJob2004
try tossing this in:

if (obj instanceof PlugIn)

to see if you are getting the expected clas type back (although someone alerady said you are not).
He's already proved that that test will evaluate to false.
 
Originally posted by: Ned Flanders
Nah mate - BlueJ (www.blueJ.org) 😀

I can't stand the 'professional' IDEs which can't view the object as it is being run (i.e I can pause the process and view the current contents of an ArrayList or Vector). Unless that feature exists in them but I cant find it....

whoooooo, 50mins left of work.
Are you implying that you can't view the contents of an ArrayList while debugging with eclipse? You definitely can, although for complicated collections types it can be a little complicated trying to drill through all the layers. The only thing better that I've seen is Visual Studio (obviously not for java) which can slap on a nice, logical view for some collections.

As for your source code, would you be willing to provide the entire project? I'm on xmas vacation now and I've got some time and it would be easier to look at the code and hack rather than ask questions based on postings here. I've got stuff like this working before but it was mostly little guided demos so this looks like fun. If you can't easily post it on the web I can pm you an email address.
 
Oh yeah, so the main Class you need to run is client.gui.Client

The classes in question are:

client.util.PluginLoader
client.Plugin

The plugin dir is /plugins (Inside is a test plugin (Test) compiled without a package statement)

thanks aGAIN!
 
Ok, I put the source back up with everything this time. The Test class was again compiled with no package statement - and then moved to the Plugins dir. The .java is inside the Client dir
 
First report:
-figured now would be a good time to investigate BlueJ. It's confusing as hell, I've dumped for eclipse 😉
-wrote a main() method for Client because you can't run it without one (I guess BlueJ likes to do magic?) 😛
-stepped through the code as provided, loading the Test.class didn't throw any exceptions but I can't tell what will happen after that because nothing is done with it

I will now start hacking a bit...
 
Second report:
-instantiated an instance of Test and successfully casted it to Plugin
-made my own kamper.KampersPlugin and put the class file in ./plugins/kamper, changed the plugins dir and got the same error as your second one (wrong name)
-changed the plugins dir back to "./plugins/" and instead of searching for class files, hardcoded "kamper.KampersPlugin" as per the original example
-I was able instantiate and initialize my plugin without any problems

I'm guessing my first analysis about the multiple loadings of the Plugin interface was correct. Also, unless you want to start doing a recursive search for plugins and don't mind testing each class for whether or not it implements Plugin (there will inevitably be support classes that you don't want to instantiate), you should put the qualified names of plugins to be loaded in some sort of configuration file. It could be a file per plugin so that you can still just drop new stuff in without updating a master list and then you could also supply some configuration items specific to that plugin. Eclipse, as far as I understand it, has a directory per plugin and probably a well known config file name within that directory.
 
Yeah, BlueJ doesn't need a main() method to run a class. Right Click -> New Client() does the trick 😀

Haha, you read my mind about the structure of the plugins - It was my goal to have a folder per plugin (The folder name being the main class name too) - thus making loading of the correct classes much easier. All the pluginLoader would do would loop the foldernames and intantize each plugin, then depending on whether the plugin had been configured (i.e enabled using the PluginManager class) call the initialize(client.gui.Client client) method which would start the plugin. Any additional files (such as plugin config files) would be handled by the plugin itself.
 
So is it working well for you now? I think your original code was pretty good, just screwed up by an oddity that disappears when you put plugins in their own location.
 
Hmm, well I basically just went back to the code you had in the first place. The only significant difference is that Plugin wasn't in the folder right above the plugin I tried to load. But it was on the same classpath...

I've attached the modified PluginLoader as well as my plugin. KampersPlugin.class sits in ./plugins/kamper at run time. Incidentally, Plugin.class is in ./plugins/client because eclipse somehow chose ./plugins as the output folder.

If this doesn't work for you, I'd start to suspect BlueJ. It's probably running its own classloader which may or may not act like a proper parent to yours. Eclipse starts up a completely new, vanilla virtual machine every time you run your app but I'm guessing BlueJ doesn't do the same.
 
Update : BLUEJ IS EVIL! Migrated my project into Netbeans and BHAM! The plugins loaded fine.

Seems Kamper, again, had the right idea about BlueJ using a custom class loader;

Thanks all!

Until my next java.ObscureErrorException ! 😀
 
Back
Top