0

With Eclpise (and other tools), it is possible to include a dependency jar inside another jar (see this answer). When Eclipse do that, it generates a custom class loader, because "classic" class loaders are not able to find a class in a jar that is inside another jar.

To create my jar (package.final.jar), I :
- Imported the jar to include (dep.jar) inside a libs/ folder in my project ;
- Added dep.jar in MANIFEST.MF -> Runtime -> Classpath (so it added the line Bundle-ClassPath: libs/dep.jar,. to my manifest) ;
- Exported my project as a deployable plug-ins and fragments.

And package.final.jar contains only this structure :

-META-INF/MANIFEST.MF
-package/-class1.class
         -class2.class
         .
         .
         .
-libs/dep.jar

So I am wondering, where is the custom class loader created by Eclipse ?

Fifi
  • 467
  • 6
  • 17
  • 'deployable plug-ins and fragments' is for Eclipse plugin-ins (or fragments). These are very different from ordinary jars. The Eclipse / OSGi plug-in classloaders deal with these. – greg-449 Aug 26 '19 at 14:38
  • @greg-449 Okay, but what is different exactly ? I can see that the manifest is different, but is there any other difference in the jar ? – Fifi Aug 27 '19 at 06:56
  • The difference in the MANIFEST.MF is key. The `Bundle-Classpath` tells the Eclipse / OSGi plug-in system how to deal with the included jars - nothing else understands this entry in the manifest. It only works when installed as an Eclipse plug-in (or another OSGi container). – greg-449 Aug 27 '19 at 06:58
  • @greg-449, Okay, it is simple as that ! So if I create a jar manually (with command-line), and put a MANIFEST.MF with `Bundle-Classpath`, the plug-in system will also know how to deal with the included jar ? – Fifi Aug 27 '19 at 07:01
  • 1
    You can build it however you like as long as the MANIFEST.MF is correct. Most Eclipse plug-ins are built using [tag:maven] + [tag:tycho] these days. In future if you are asking about Eclipse plug-ins please say so and use the [tag:eclipse-plugin] tag. – greg-449 Aug 27 '19 at 07:04

2 Answers2

1

For Eclipse plug-ins the Bundle-ClassPath entry in the plug-in's MANIFEST.MF tells the Eclipse / OSGi system which classes and jars in the main plug-in jar are part of the class path.

There is no extra code added to the plug-in jar, the Eclipse class loaders deal with the included jars.

So you can build the jar however you like as long as the MANIFEST.MF is correct. Using maven + Eclipse tycho is common these days.

greg-449
  • 109,219
  • 232
  • 102
  • 145
0

You should have the following folder inside your jar: org/eclipse/jdt/internal/jarinjarloader

Containing the Classloader etc.:

  • JIJConstants.class
  • JarRsrcLoader$ManifestInfo.class
  • JarRsrcLoader.class
  • RsrcURLConnection.class
  • RsrcURLStreamHandler.class
  • RsrcURLStreamHandlerFactory.class

You can also check it if you look into the META-INF/MANIFEST.MF-File to see what Main-Class is set

Sebastian
  • 51
  • 4
  • I don't have this folder. Maybe my question was not specific enough. I updated it. – Fifi Aug 26 '19 at 14:13
  • My solution only "works" if you export it as "Runnable Jar File". When there is no specific item in your main-class-Manifest-Entry I would suggest that the platform you're running your jar-files on has the ClassLoader included. – Sebastian Aug 26 '19 at 14:28