Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 321321

Summary: cannot load plugin dynamically
Product: [Eclipse Project] Equinox Reporter: Stella Levin <stella_levin2003>
Component: FrameworkAssignee: equinox.framework-inbox <equinox.framework-inbox>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3 CC: pwebster, remy.suen, tjwatson
Version: 3.6   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
myRcp and myplugin ecilpse project directories
none
workspace directory
none
export plugin directory none

Description Stella Levin CLA 2010-07-30 06:14:59 EDT
Build Identifier: M20080911-1700 and M20090917-0800

Linux 64
I need to load plugin when some condition is satisfied. I used BundleContext::install and Bundle::start and it always fails with exceptions 
org.osgi.framework.BundleException: The activator myplugin.Activator for bundle myplugin is invalid
Caused by: java.lang.ClassNotFoundException: myplugin.Activator

Reproducible: Always

Steps to Reproduce:
1.Create "Hello Word" plugin development project
2.Export the plugin and close the project
3.Create RPC Main project for rpc development
4. Add the following code in Activator::start(BundleContext context)        
        String location = "reference:file:<myplugin full path>";
        Bundle b = context.installBundle(location);
        try {
                // start the plugin explicitly
                b.start(Bundle.START_TRANSIENT);
                System.out.println("-I- Started bundle myplugin");
        }
        catch ( BundleException e ) {
                // Handle errors
                 e.printStackTrace();
                 System.out.println("-E- Error load bundle myplugin");
        }
5. Run rpc and get exception on startup.
Comment 1 Paul Webster CLA 2010-07-30 07:00:16 EDT
What exception?

PW
Comment 2 Thomas Watson CLA 2010-08-02 09:09:47 EDT
Does the bundle you install have the myplugin.Activator class included in it?  Could you attach a testcase, I cannot reproduce with my own bundle.
Comment 3 Stella Levin CLA 2010-08-02 09:32:29 EDT
Created attachment 175710 [details]
myRcp and myplugin ecilpse project directories

Hi, I created tar gzip for eclipse directories of myRpc and myplugin. You may see the exact contents of the classes. Do you try to reproduce on Linux 64?
Regards, Stella
Comment 4 Paul Webster CLA 2010-08-02 09:33:24 EDT
I was also able to get it working with the 2 plugin templates mentioned, and the code from below.

The only change I had to make was to add extra plugins to the launch config (org.eclipse.jface.text in my case) so that the bundle could load.

PW
Comment 5 Paul Webster CLA 2010-08-16 13:06:09 EDT
(In reply to comment #3)
> Created an attachment (id=175710) [details]
> myRcp and myplugin ecilpse project directories
> 

You use this path: /home/slevin/kfir/pw/myplugin

Is this the location of your plugin in your workspace?  if that's the case, this will not work.

Please attach a version of the plugins that would work when your product is exported (hint, you should see myplugin_1.0.0.jar) and then re-open.

PW
Comment 6 Paul Webster CLA 2010-08-16 22:38:42 EDT
.
Comment 7 Stella Levin CLA 2010-08-17 02:51:38 EDT
Hi,
The directory in context.installBundle(location) is a directory where the plugin was exported. 
Attached files: pw.tgz - workspace, pw_2.tgz - export directory.
Thanks, Stella
Comment 8 Stella Levin CLA 2010-08-17 02:58:13 EDT
>The only change I had to make was to add extra plugins to the launch config
>(org.eclipse.jface.text in my case) so that the bundle could load.

I added org.eclipse.jface.text to run configuration of the myRpc. It was not helpful. Did you mean this?
Thanks, Stella
Comment 9 Paul Webster CLA 2010-08-17 05:55:52 EDT
(In reply to comment #7)
> Attached files: pw.tgz - workspace, pw_2.tgz - export directory.
> Thanks, Stella

It looks like you forgot to attach these files.

PW
Comment 10 Stella Levin CLA 2010-08-17 06:49:29 EDT
Created attachment 176773 [details]
workspace directory
Comment 11 Stella Levin CLA 2010-08-17 06:50:42 EDT
Created attachment 176774 [details]
export plugin directory
Comment 12 Paul Webster CLA 2010-08-17 15:31:58 EDT
pw_2 is not a valid plugin, you cannot load it.

You need to take your myplugin from your original attachment and use File>Export...>Deployable plugins and fragments.

The myplugin_1.0.0.jar that creates should be loadable by your activator.

PW
Comment 13 Paul Webster CLA 2010-08-17 15:32:28 EDT
(In reply to comment #12)
> pw_2 is not a valid plugin, you cannot load it.
>

That should be pw_2/myplugin is not a valid plugin.

PW
Comment 14 Paul Webster CLA 2010-08-18 06:01:49 EDT
Please try with a deployed plugin.

PW
Comment 15 Stella Levin CLA 2010-08-18 10:03:33 EDT
Hi Paul, I get it working when use fullpath including jar:
       String location = 
            "reference:file:<full path>/myplugin/plugins/myplugin_1.0.0.jar";
        Bundle b = context.installBundle(location);

Error was in writing location as a directory of exported plugin :
       String location = "reference:file:/home/slevin/kfir/pw_3/myplugin";
Thanks a lot. Stella
Comment 16 Paul Webster CLA 2010-08-18 10:28:11 EDT
(In reply to comment #15)
> Hi Paul, I get it working when use fullpath including jar:
>        String location = 
>             "reference:file:<full path>/myplugin/plugins/myplugin_1.0.0.jar";
>         Bundle b = context.installBundle(location);

That means it's working when you export your plugin correctly (which is the only way it's supposed to work).

closed.
PW