Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » RCP strange behavior with XMLDecoder
RCP strange behavior with XMLDecoder [message #303378] Sun, 14 May 2006 05:18 Go to next message
Eclipse UserFriend
Originally posted by: sami.xxxxxxxx.com

Hi,

I'm using java 1.5.0 beta 2. and eclipse 3.1.
I have developped a first plugin 1 that use XMLDecoder in a method called
load.
Next, I have developped a plugin 2 dependent on plugin 1 that make use of
plugin 1 load method and tested it with success.
Plugin 2 test is the main method that use basic SWT widget display, shell
button that call the load method from plugin 1.

Then I developped an RCP dependant on plugin 1 and call the same method
load from plugin 1 the same way I did for plugin 2.

In the RCP an exception ("ClassNotFoundException")
Here is a summary of the plugin 1 load method

load(... input){
// the following line give the decoder variable its good value
XMLDecoder decoder = new XMLDecoder(input, null, null) ;

// the following line throw an exception "ClassNotFoundException"
Object obj = decoder.readObject();
}

I have then developped others plugins and rcp that use plugin 1.
All plugin using SWT and plugin 1 run with success.
All RCP throw the same exception

Any idea.
Many thanks for your answers
sami
Re: RCP strange behavior with XMLDecoder [message #303410 is a reply to message #303378] Mon, 15 May 2006 09:14 Go to previous messageGo to next message
Eclipse UserFriend
Sami wrote:
> Hi,
>
> I'm using java 1.5.0 beta 2. and eclipse 3.1.
> I have developped a first plugin 1 that use XMLDecoder in a method
> called load.
> Next, I have developped a plugin 2 dependent on plugin 1 that make use
> of plugin 1 load method and tested it with success. Plugin 2 test is the
> main method that use basic SWT widget display, shell button that call
> the load method from plugin 1.

If it has a main method, then it's not a plugin ... do you mean you've
developed projects? Or you've made plugins, but you're just running
them as java applications (i.e. main method calls classes and methods
from "plugin 1")?


> Then I developped an RCP dependant on plugin 1 and call the same method
> load from plugin 1 the same way I did for plugin 2.
>
> In the RCP an exception ("ClassNotFoundException") Here is a summary of
> the plugin 1 load method

An RCP app will be using real plugins. That means that plugin classpath
restrictions apply.

Amongst other things, if you've included 3rd party jars you need to be
very specific about how (I use a list like
http://wiki.eclipse.org/index.php/PDE )

Also, if plugin 2 depends on plugin 1, then plugin 1 cannot instantiate
any objects from plugin 2. This problem often shows itself when you
have factory patterns, where plugin 1 contains the main engine and
plugin 2 is providing implementation objects.

Later,
PW
Re: RCP strange behavior with XMLDecoder [message #303423 is a reply to message #303410] Mon, 15 May 2006 11:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sami.xxxxxxxxxx.com

I have first turned a 3rd party jar into a plugin 0 using option 1 method
as explained in http://wiki.eclipse.org/index.php/PDE )
This plugin 0 export all its pakages.This plugin does not contain a main
method.

The I have made a plugin 1 that uses plugin 0 (via its PED dependencies
tab) and export some of its packages. This is actualy in my workspace and
not exported for deployment. This plugin does not contain a main method.
It export a package that contain a class including a method named load
that in turn create and use XMLDecoder

Then I have made a plugin 2 that use pluging 1.
This project has 2 packages
say plugin2.package1 and say plugin2.package2

plugin2.package1 contains one classX including a method that need a
Display param. This class has methods that instanciates objects from
plugin 1 and display them in an SWT shell using gridlayout, button etc ...
This package is exported (runtime tab).

plugin2.package2 contains a main method (for test purposes) and is not
exported. I run the test using : selected class containing main method and
run as => SWT application
and the test is successful.

Finally, I have developped an RCP (or even genered one via existing
templates) and added plugin2.package1 (PDE dependencies tab).
Then, in the Application class, I create an object from the
plugin2.package2.classX and call its method giving it the display param.

Result : the SWT shell open well and when I click the button that call a
method in plugin 2 which in turn call the famous load method in plugin 1,
then the new XMLDecoder(...) inside the load method throw an exception and
return null ...
This worked well with my plugin2.package2 test using main.

Thanks for your answers.
sami
Re: RCP strange behavior with XMLDecoder [message #303434 is a reply to message #303423] Mon, 15 May 2006 13:42 Go to previous messageGo to next message
Eclipse UserFriend
sami wrote:

>
> plugin2.package1 contains one classX including a method that need a
> Display param. This class has methods that instanciates objects from
> plugin 1 and display them in an SWT shell using gridlayout, button etc ...
> This package is exported (runtime tab).

This is constrained by the runtime bundle classpath in the manifest.

>
> plugin2.package2 contains a main method (for test purposes) and is not
> exported. I run the test using : selected class containing main method
> and run as => SWT application
> and the test is successful.

This has nothing to do with eclipse, it's pretending that it's just a
java app ... i.e. the fact that it runs means nothing.

> Finally, I have developped an RCP (or even genered one via existing
> templates) and added plugin2.package1 (PDE dependencies tab).
> Then, in the Application class, I create an object from the
> plugin2.package2.classX and call its method giving it the display param.

So assuming the dependencies are RCP -> plugin2 -> plugin1 -> plugin0,
then you need to make sure that nothing tries to load a class "down" the
dependency chain.

i.e. plugin0 is not trying to do a
loadClass("class.in.plugin1.MyClass"). But plugin1 could load a class
from plugin0.

Also, when you "deploy" you have to ship all of the plugins. You said
"plugin1 ...and not exported for deployment." It must be deployed or it
won't run.


> Result : the SWT shell open well and when I click the button that call a
> method in plugin 2 which in turn call the famous load method in plugin
> 1, then the new XMLDecoder(...) inside the load method throw an
> exception and return null ...

Which line throws the ClassNotFoundException? What is the code on that
line, and which plugin is it in?

> This worked well with my plugin2.package2 test using main.

Like I said, this is using (more or less) vanilla java classloading, and
demonstrates nothing about your plugin problem.

Later,
PW
Re: RCP strange behavior with XMLDecoder [message #303497 is a reply to message #303434] Tue, 16 May 2006 12:43 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sami.xxxxxxxxxx.com

Paul Webster wrote:

> sami wrote:

>>
>> plugin2.package1 contains one classX including a method that need a
>> Display param. This class has methods that instanciates objects from
>> plugin 1 and display them in an SWT shell using gridlayout, button etc ...
>> This package is exported (runtime tab).

> This is constrained by the runtime bundle classpath in the manifest.

Note that my plugins 0,1 and 2 are just plugin "library type". They are
not intented to be extended.

>>
>> plugin2.package2 contains a main method (for test purposes) and is not
>> exported. I run the test using : selected class containing main method
>> and run as => SWT application
>> and the test is successful.

> This has nothing to do with eclipse, it's pretending that it's just a
> java app ... i.e. the fact that it runs means nothing.
I agree but the dependencies plugin2 -> plugin1 -> plugin0 work well.

>> Finally, I have developped an RCP (or even genered one via existing
>> templates) and added plugin2.package1 (PDE dependencies tab).
>> Then, in the Application class, I create an object from the
>> plugin2.package2.classX and call its method giving it the display param.

> So assuming the dependencies are RCP -> plugin2 -> plugin1 -> plugin0,
> then you need to make sure that nothing tries to load a class "down" the
> dependency chain.

> i.e. plugin0 is not trying to do a
> loadClass("class.in.plugin1.MyClass"). But plugin1 could load a class
> from plugin0.

Plugin 0 was made by turning the jar "apache.commons.codec" (last version
1.3) using option 1 method in http://wiki.eclipse.org/index.php/PDE
So I thinks there is no down class load


> Also, when you "deploy" you have to ship all of the plugins. You said
> "plugin1 ...and not exported for deployment." It must be deployed or it
> won't run.
Note that I'm actually just testing my RCP project under eclipe ide.


>> Result : the SWT shell open well and when I click the button that call a
>> method in plugin 2 which in turn call the famous load method in plugin
>> 1, then the new XMLDecoder(...) inside the load method throw an
>> exception and return null ...

> Which line throws the ClassNotFoundException? What is the code on that
> line, and which plugin is it in?

Plugin 1 import java.beans.XMLDecoder which contain a XMLDecoder class
In my plugin 1, I have a class to persist xml object and a method (load)
with the following lines of code :

public Object load (InputStream xmlIn) throws PersistenceServiceException {
XMLDecoder decoder = null;
try {
decoder = new XMLDecoder(new BufferedInputStream(xmlIn, BUFFERSIZE),
null, null);

Object obj = decoder.readObject(); <=== here happen my exception
}

>> This worked well with my plugin2.package2 test using main.

> Like I said, this is using (more or less) vanilla java classloading, and
> demonstrates nothing about your plugin problem.

> Later,
> PW
Re: RCP strange behavior with XMLDecoder [message #303499 is a reply to message #303497] Tue, 16 May 2006 14:27 Go to previous messageGo to next message
Eclipse UserFriend
sami wrote:
> Paul Webster wrote:
>
>> sami wrote:
>
>
>>>
>>> plugin2.package1 contains one classX including a method that need a
>>> Display param. This class has methods that instanciates objects from
>>> plugin 1 and display them in an SWT shell using gridlayout, button
>>> etc ...
>>> This package is exported (runtime tab).
>
>
>> This is constrained by the runtime bundle classpath in the manifest.
>
>
> Note that my plugins 0,1 and 2 are just plugin "library type". They are
> not intented to be extended.

bundle classpath and manifest are about running the plugin and loading
the classes. plugin.xml and extension points are about extending.

> I agree but the dependencies plugin2 -> plugin1 -> plugin0 work well.

pretending they're java projects their dependencies work well ... I'm
just saying that is irrelevant as far as determining if their plugin
dependencies are working well.

>
>> i.e. plugin0 is not trying to do a
>> loadClass("class.in.plugin1.MyClass"). But plugin1 could load a class
>> from plugin0.
>
>
> Plugin 0 was made by turning the jar "apache.commons.codec" (last
> version 1.3) using option 1 method in http://wiki.eclipse.org/index.php/PDE
> So I thinks there is no down class load


> Plugin 1 import java.beans.XMLDecoder which contain a XMLDecoder class
> In my plugin 1, I have a class to persist xml object and a method (load)
> with the following lines of code :
>
> public Object load (InputStream xmlIn) throws PersistenceServiceException {
> XMLDecoder decoder = null;
> try {
> decoder = new XMLDecoder(new BufferedInputStream(xmlIn, BUFFERSIZE),
> null, null);
>
> Object obj = decoder.readObject(); <=== here happen my exception }


OK, so plugin1 is calling decoder.readObject() ... what object is it
trying to read out of your xmlIn stream? Basically, readObject() is
causing plugin1 to call loadClass(*) somewhere. If the object it is
trying to read is in plugin0 or plugin1, then it should be OK, if it's
defined in plugin2, then it will fail.

From my first post:
Also, if plugin 2 depends on plugin 1, then plugin 1 cannot instantiate
any objects from plugin 2. This problem often shows itself when you
have factory patterns, where plugin 1 contains the main engine and
plugin 2 is providing implementation objects.

Later,
PW
Re: RCP strange behavior with XMLDecoder [message #303521 is a reply to message #303499] Wed, 17 May 2006 04:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sami.xxxxxxxxxx.com

Hi,

> From my first post:
> Also, if plugin 2 depends on plugin 1, then plugin 1 cannot instantiate
> any objects from plugin 2. This problem often shows itself when you
> have factory patterns, where plugin 1 contains the main engine and
> plugin 2 is providing implementation objects.

> Later,
> PW

In some conditions, plugin 1 was trying to instantiate objects from plugin
2.

Thanks a lot Paul
sami
Re: RCP strange behavior with XMLDecoder [message #303546 is a reply to message #303521] Wed, 17 May 2006 07:11 Go to previous message
Eclipse UserFriend
sami wrote:
>
> In some conditions, plugin 1 was trying to instantiate objects from
> plugin 2.
>
> Thanks a lot Paul
> sami
>

So the solution to this is to use buddy classloading. It allows plugin1
to search the classpath of dependent plugins without having to know
about them. Search the Help>Help contents for buddy classloading and/or
3rd party libraries.

Later,
PW
Previous Topic:Launch my own Eclipse View
Next Topic:Accessing field editors on a FieldEditorPreferencePage
Goto Forum:
  


Current Time: Sun Jun 08 18:48:04 EDT 2025

Powered by FUDForum. Page generated in 0.04161 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top