Re: Dynamically load laf




>You realise you have to put the jars file names in the classpath, not
>just the directory they are in. I seem to remember a feature in 1.6 for
>allowing specifying the directory only, but don't quote me on that.

yes, I have realized that, and that is basically the root of the
problem here.

>URLClassLoader should do just as well. I'm not certain what your problem
>with the classpath was, but it is probably worthwhile sorting that one
>out first.

yeah, I have realized that, and scrapped my own classloader.

>Perhaps it might help if we saw the code of how you are attempting to
>use the class loader to install the PL&F.
Currently I am doing this:

if(dir.exists()){
ClassLoader loader= ClassLoader.getSystemClassLoader();
java.net.URLClassLoader ul=null;
if(loader instanceof java.net.URLClassLoader){
ul=(java.net.URLClassLoader)loader;
}

File[] lafs= dir.listFiles();
int jarnum=0;
for(int i=0;i<lafs.length;i++){
if (lafs[i].getName().endsWith(".jar")) {
jarnum++;
}
}
java.net.URL[] url= new java.net.URL[jarnum];
int j=0;


for(int i=0;i<lafs.length;i++){
if(lafs[i].getName().endsWith(".jar")){
int ind=lafs[i].getName().lastIndexOf(".jar");
url[j]= lafs[i].toURL();
ul= new java.net.URLClassLoader(url);

j++;
Class c=ul.loadClass(lafs[i].getName().substring(0,ind));

UIManager.setLookAndFeel((javax.swing.LookAndFeel)c.newInstance());
}
}

from what I understand the line ul= new URL.... is actually quite
stupid, since I basically just change the local variable and not the
instance being used at other places. Ideally I would just add the new
url to the existing one, but as I said it is not possible.
Some of this code is not very good, but I will clean it up and make it
smarter and better when I understand what I am doing :)

>You want to do all this for every class loaded? For one thing, you are
>not closing your input streams, even in the normal case. Using a ZipFile
>would probably be better, too.
actually this is pretty much a work in progress, once I got it working
I would clean it up, and look at things like what you mention here.
The same with the code pasted above. I want to solve the problem
first, only then can I begin to optemize away things not needed, or
done in a stupid way.

.



Relevant Pages

  • Re: Cleaning up PATHs?
    ... which I'd like to clean. ... awk is the right tool here. ... CLASSPATH=$(printf %s "$CLASSPATH" | ... That fails if the last unique element ends in a newline character. ...
    (comp.unix.shell)
  • Re: ZX81 Tapes.
    ... probably because I'm doing something stupid:) ... Exception in thread "main" java.lang.NoClassDefFoundError: ... tapeutil/zx81/Convert SampleToP ... You need to set your classpath to point to the tapeutils.jar file - ...
    (comp.sys.sinclair)
  • Re: Java and SOAP
    ... I found the problem: I'm stupid... ... I was adding jar files in ... the Tools->Options->Ant Settings, but the good way to do it was using ... additional classpath ant's option isn't really a way to indicate ...
    (comp.lang.java.programmer)
  • How to add to classpath using java -cp in SunOS 8.5?
    ... I have not used Unix in a LONG time, so pardon the seemingly stupid ... 'java -cp' command preferably. ... When I attempt to do so, my classpath does not change and there is no ...
    (comp.unix.solaris)
  • Re: ZX81 Tapes.
    ... probably because I'm doing something stupid:) ... Exception in thread "main" java.lang.NoClassDefFoundError: ... tapeutil/zx81/Convert SampleToP ... You need to set your classpath to point to the tapeutils.jar file - either ...
    (comp.sys.sinclair)