Bug 197996 - Require-Bundle for osgi bundle does not give correct classpath
Summary: Require-Bundle for osgi bundle does not give correct classpath
Status: RESOLVED DUPLICATE of bug 135012
Alias: None
Product: PDE
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: PDE-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-07-26 13:01 EDT by Max Rydahl Andersen CLA
Modified: 2007-07-30 09:27 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Max Rydahl Andersen CLA 2007-07-26 13:01:40 EDT
Build ID: I20070625-1500

Steps To Reproduce:
1. put org.mozilla.xpcom into your eclipse plugins directory (http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/1.8.1.3/contrib/eclipse/org.mozilla.xpcom_1.8.1.3-20070320.jar)

2. Create a new plugin, lets call it X
3. Add org.mozilla.xpcom to this plugin X
4. Import of org.mozilla.* should now be possible but it is not

5. Go and import the org.mozilla.xpcom as a binary project (via the plugins view)

6. Now classes found in org.mozilla.xpcom can be used.

Why can't PDE pick up the classes ? 


More information:
Comment 1 Philippe Ombredanne CLA 2007-07-26 13:05:54 EDT
Could this be linked to the use of : 
DynamicImport-Package: org.mozilla.xpcom
in
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt/META-INF/MANIFEST.MF?revision=1.31&view=markup
?
Comment 2 Wassim Melhem CLA 2007-07-26 13:11:53 EDT
Tom, this is working as designed, right?
Comment 3 Alex Blewitt CLA 2007-07-26 13:57:15 EDT
When you drop it into the plugins directory, are you doing a restart?

Also note that if you change the target platform then you need to do a 'refresh' as otherwise PDE doesn't pick up on the changes. I wonder if that's what is happening here.

Alex.
Comment 4 Thomas Watson CLA 2007-07-26 14:08:09 EDT
This is happenning because org.mozilla.xpcom has an inner jar
MozillaInterfaces.jar which contains the org.mozilla.* packages.  When this
bundle is a jar'ed bundle in your target PDE (or JDT) cannot handle the inner
jar for classpaths.  There is a JDT or PDE bug already open about this.  This
bug should be dup'ed to that bug.
Comment 5 Wassim Melhem CLA 2007-07-26 14:14:13 EDT
sorry to have bothered you, Tom.  The Dynamic-ImportPackage reference in comment 1 was a red herring.

*** This bug has been marked as a duplicate of bug 135012 ***
Comment 6 Max Rydahl Andersen CLA 2007-07-27 05:25:20 EDT
Why is this jar different than any other nested jar ?

e.g. I have many plugins that have nested jars in it to have access to e.g. hibernate, log4j, etc.
Comment 7 Thomas Watson CLA 2007-07-27 09:37:41 EDT
Do you export packages from the nested jars?  The issue is PDE/JDT does not handle placing inner jars from jar'ed bundles onto the classpath of clients trying to use Import-Package or Require-Bundle to access the classes.

Notice that in the eclipse sdk the bundles which have nested jars are shipped as "directory" bundles.  This is to work around this tooling bug.  If your bundle only uses the classes from the inner jar (ummm) internally (i.e. does not specify Export-Package for any of its content) then it is fine for the bundle to be jar'ed.  This is because clients should never have access to the inner jar.  Once you try to expose the inner jar to clients for compilation purposes then your bundle will have to be a "directory" or "exploded" bundle instead of a jar'ed bundle to work around this tooling bug.
Comment 8 Max Rydahl Andersen CLA 2007-07-27 11:12:39 EDT
yes in my own bundles i simply include the jar on bundle-classpath and export the packages.

Just like e.g. org.apache.ant does it.

I guess xpcom should do the same and it would work?


Comment 9 Jeff McAffer CLA 2007-07-27 21:23:40 EDT
re comment 7...

This is not a tooling "bug".  AFAIK there are no java compilers that will go into nested JARs to discover classes.  Yes, JDT/PDE could work around this limitation and extract the nested JARs etc.  Contributions for this caching infrastructure would likely be welcomed.

> If your bundle only uses the classes from the inner jar (ummm) internally 
> (i.e. does not specify Export-Package for any of its content) then it is fine 
> for the bundle to be jar'ed.  
That is not entierly true.  Say there is a class A in the exported packages and some class B in some internal JAR.  If A subclasses B then someone referencing A (e.g., to extend it) will have to see B at compile time.
Comment 10 Max Rydahl Andersen CLA 2007-07-28 05:24:28 EDT
I'm confused, if this is not a bug why does the bundle work at runtime ?

Why is every other kind of nested jar fully functional ?

What is special about this xpcom bundle (except that it doesn't export packages, but that would still not be enough for a compiler to read it) ?
Comment 11 Thomas Watson CLA 2007-07-30 09:02:18 EDT
(In reply to comment #10)
> I'm confused, if this is not a bug why does the bundle work at runtime ?

Let me clarify comment 7.  I'm stating this is definitely *not* a runtime bug.  The tooling does not know how to handle inner jars, which are jar'ed in another jar, for compilation purposes.  As Jeff points out this is true for any build system that we know of JDT, javac, maven, ant etc.  Call it a tooling bug or a restriction, I think the end user does not care.

> 
> Why is every other kind of nested jar fully functional ?
> 
> What is special about this xpcom bundle (except that it doesn't export
> packages, but that would still not be enough for a compiler to read it) ?
> 

Actually, it is the opposite.  The xpcom bundle *is* exporting packages from the inner jar, which is jar'ed in another jar.  Currently the build tools do not know how to use inner jars packaged in another jar for compilation.  Therefore the packages exported by the xpcom bundle cannot be found at compilation time.
Comment 12 Max Rydahl Andersen CLA 2007-07-30 09:06:42 EDT
aaah...so if one would unzip it then it is expected to work ?

(in other words unpack="true" in feature.xml is relevant)
Comment 13 Max Rydahl Andersen CLA 2007-07-30 09:23:03 EDT
ok - this is solved and it's just me being blind.

unzip the plugin into a directory with the same name (sans .jar) and it work (as expected).

I just (again) got caught by the fact that an updatesite .jar is zipped and then in feature.xml it is stated if it should be unpacked or not...
Comment 14 Thomas Watson CLA 2007-07-30 09:27:45 EDT
(In reply to comment #12)
> aaah...so if one would unzip it then it is expected to work ?
> 
> (in other words unpack="true" in feature.xml is relevant)
> 

Yup, this is currently what others do in the same situation.

Although a better alternative is to insert the bundle manifest directly into
the MozillaInterfaces.jar and use it directly as a bundle instead of packaging
it into another bundle as a inner jar.  This is what the orbit project does for
most of the 3rd party code used in eclipse.  See:

http://wiki.eclipse.org/Adding_Bundles_to_Orbit#Adding_a_library_for_the_first_time