We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › Java help request by Mother developer
Page Index Toggle Pages: 1
Java help request by Mother developer (Read 616 times)
Java help request by Mother developer
Jan 22nd, 2009, 12:30pm
 
Hi!

In my efforts of further developing the Mother program (GPL host for VJing with processing sketches, have a look at www.onar3d.com), I’ve run into some trouble that the Java ninjas in this forum might be able to help me out with :)

Briefly, what I’m looking for is a way to dynamically alter the location where the ClassLoader looks for new classes, preferable including looking within jar files.

What my program does, is treat processing sketch .jar files as plugins. I instantiate the sketch using Class.forname(), to which I give a new URLClassLoader created with the path to the sketches jar file like this:

URLClassLoader cl = new URLClassLoader( new URL[] {sketchPath.toURI().toURL()} );

This works fine for sketches that do not use external libraries (say toxi’s geomutils.jar for example), or sketches that have been exported from eclipse so that they include the libraries in the .jar file.

However the Processing IDE does not pack sketches in this manner, and so when I load such a sketch in my program, I get a “java.lang.NoClassDefFoundError: toxi/geom/Vec3D” in the case where the sketch was using toxi’s geomutils.jar.

What I would like is a way to programmatically, when my application is starting up, scan a user-defined folder with library jar’s, and make sure that the ClassLoader takes these into account.

I’ll of course keep looking for a solution, and in the meantime I’d be grateful for any tips you may have!

Thanks,
Ilias B.
Re: Java help request by Mother developer
Reply #1 - Jan 22nd, 2009, 3:48pm
 
To tell Java to use all jars in a folder (or set of folders), I use the java.ext.dirs property, for example like: -Djava.ext.dirs=C:\Java\UsefulLibs;E:\Sketches\libraries
Re: Java help request by Mother developer
Reply #2 - Jan 22nd, 2009, 3:56pm
 
Thanks for the quick reply!

I know about that, the trouble is that that is a compilation-time setting, and here I need a runtime solution.

It seems I've just found a solution, from a chance discussion with a Java programmer over lunch:

There is nothing that stops me from using URLS to more than one .JAR files when i create the URLClassLoader.

I just tried it and it works! I just list all .jar files related to the sketch individually when I instantiate the URLClassLoader.

Obvious if you know how class loaders work, but it took quite a bit of searching for me to learn.

...So unless I revive this thread consider it closed, my first attempts with this solution worked fine!

Thank you all for your time!

Mother is now very near it's 0.3 release :)
Re: Java help request by Mother developer
Reply #3 - Jan 22nd, 2009, 6:05pm
 
No, it is a runtime switch, ie. a parameter I give to Java when I run the program.
Re: Java help request by Mother developer
Reply #4 - Jan 22nd, 2009, 6:42pm
 
You're right.

What I meant is that I do not know of any way to make an easily deployable application using that command. In a manner that allows users to just download the program, double-click on and icon and run it, without knowing what java is; In a spirit similar to that of Processing.

I've found a good way to do this now though, as I described in my previous post.

Thank you for your help!

Page Index Toggle Pages: 1