Re: Troubles running samples

Brennan Stehling <[email protected]>
Newsgroups gmane.comp.embedded.carlsbad-cubes
Message-ID <[email protected]>
What is happening here is a tricky nuance with
classloaders.  It will be helpful to understand what
is  going on here to avoid further trouble.

When the Jar is in the ${JAVA_HOME}/lib/ext it uses
the Extensions classloader but for classes in the
CLASSPATH will be loaded by the System classloader.

I am reading a book by Stuart Halloway on classloaders
and reflection and it covers the nuance which is
likely causing you trouble in this case.  In one
example he shows how to get the classloader for the
calling class...

YourObject.class.getClassLoader();

but you can also just get the SystemClassLoader...

ClassLoader.getSystemClassLoader();

If SwixML tries to load a resource using the first
method above, which will use the Extensions
classloader, it will not find it due to the visibility
rules of classloaders.

I have not looked at the internals of SwixML but
placing your code and SwixML.jar into the CLASSPATH
will cause everything to be loaded by the System
classloader and prevent trouble.

But I can see the advantage of placing it in lib/ext.

- Brennan

--- Olivier Poppon <[email protected]> wrote:
> Well I don't know what to think about it.
> 
> I removed swixml.jar from the
> /Library/Java/Extensions directory 
> (leaving there just jdom.jar), and I run that :
> 	java -classpath .:../build/swixml.jar Actions
> 
> Which worked fine.
> 
> I am glad in some way, but I would like to
> understand why it ddidn't 
> work. I usually put all the .jar that will be shared
> among applications 
> in java/Extension.
> 
> Thanks for your help everyone (Kate especially)
> 
> Olivier
> 
> On 2 mai 04, at 19:32, masukomi wrote:
> 
> > There's a weird bug in SwiXml that we haven't been
> able to track down 
> > yet.  Personally I think it's something in j2se
> but....
> >
> > The symptoms you've described sound similar to
> what I've seen with 
> > this bug. Basically, sometimes saying
> .render("some/valid/path.xml") 
> > just doesn't work. It can't find the file. I've
> had two almost 
> > identical classes side by side and had one work
> and one not. I can't 
> > explain it.  I've looked at the SwiXml source and
> it was doing 
> > everything correctly. The way I get around it is
> to never specify a 
> > path that way. Instead I always use .render(new 
> > File("some/valid/path.xml")) which is arguably not
> the most efficient 
> > way to specify it but it's the one that requires
> the least typing.
> >
> > I can't comment on the icons issue without seeing
> the xml and knowing 
> > where the icons are and all that.
> >
> > -Kate
> >
> >
> >
> > On May 2, 2004, at 12:49 PM, Olivier Poppon wrote:
> >
> >> Hi,
> >>
> >> I have just discovered SwiXml and I would really
> start playing with 
> >> it, but I have a few problems just running the
> examples.
> >> I have seen several similar messages in the
> mailing archives, but 
> >> there was no proper answer.
> >>
> >> I am using Mac OS X 10.3, with java 1.4.2.
> >> I have put the swixml.jar in the
> /Library/Java/Extensions directory 
> >> (which add it automatically to the CLASSPATH).
> >>
> >> Then I go to the "samples" directory of swiXml. I
> compile all the 
> >> .java.
> >> Then I try to run one :
> >> 	olivier@Moon:~/Java/swixml_139/samples $ java
> Actions
> >> I get this:
> >> 	java.io.IOException: Resource could not be found
> xml/actions.xml
> >>
> >> I tried using a classpath like : java -classpath
> .:xml Actions, but 
> >> it does not work either.
> >>
> >> But if I change in Actions.java the instruction
> to load the xml file 
> >> from this :
> >>       swix = new SwingEngine( this );
> >>       swix.render( "xml/actions.xml" );
> >> to this:
> >> 		import org.jdom.input.SAXBuilder;
> >> 		...
> >>       swix = new SwingEngine( this );
> >>       swix.render( new
> SAXBuilder().build("xml/actions.xml") );
> >>
> >> Then it "works", as I can see the window/frame of
> the application.
> >>
> >> However, I see no icons in the menu bar
> >> (I also tried to run it using a classpath like :
> java -classpath 
> >> .:icons)
> >>
> >> and the combo does not work (there is a reference
> to it inside the 
> >> actions.xml as <combobox initclass="ComboModel"
> Action="petAction" 
> >> PrototypeDisplayValue="1234567890|1234567890"/>),
> and I have this 
> >> error :
> >> 	initclass not instantiated : 
> >> ComboModeljava.lang.ClassNotFoundException:
> ComboModel
> >>
> >> This ComboModel class is in the same directory as
> Actions.
> >>
> >> Can anyone help me on this ?
> >>
> >> Thanks,
> >>
> >> Olivier
> >>
> >>
> >> _______________________________________________
> >> Forum mailing list
> >> [email protected]
> >>
>
http://carlsbadcubes.com/mailman/listinfo/forum_carlsbadcubes.com
> >>
> >>
> >
> >
> > _______________________________________________
> > Forum mailing list
> > [email protected]
> >
>
http://carlsbadcubes.com/mailman/listinfo/forum_carlsbadcubes.com
> >
> 
> 
> _______________________________________________
> Forum mailing list
> [email protected]
>
http://carlsbadcubes.com/mailman/listinfo/forum_carlsbadcubes.com



	
		
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs  
http://hotjobs.sweepstakes.yahoo.com/careermakeover
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.