1

I have two two projects, let's call them project A and B. Project A uses Project B as a library-project and project B has a "library.jar". This library is not exported by project B. However a third party library used by Project A can use the "library.jar" from project B.

How is this possible?

If I create a class in Project A which tries to reference this exact library it can't import this library, but an imported library can?

It definitely is using that library, because if I remove the library from Project Bs buildpath it won't work for the library in project A either.

Mazen
  • 203
  • 2
  • 15
  • Are these Eclipse plugin projects? Plain Java projects? Are you using Eclipse itself to compile everything? – nitind Aug 22 '17 at 01:23

2 Answers2

1

the "exported" flag is an IDE exclusive setting to manage (the dependencies) of your Projects properly. At compiletime every class from your classpath can be used, so technically your Project A can use "library.jar" but your IDE settings prevent you from doing this.

Raphael
  • 51
  • 5
1

Exported means API, not exported means internal:

The term exported comes from OSGi/Plug-in development (see Eclipse help: Plug-in Runtime) and refers to visibility: exported build class entries are visible in projects that have that project in the build path. Not exported build path entries are in upstream projects part of the build path, but are not visible (can not be referenced in the source code).

Eclipse has its own compiler that supports modularization at compile time (developed for OSGi but offered in a simpler way via required projects and export flags also for plain Java). If you do not use OSGi you will only have a flat build path without modularization at runtime.

howlger
  • 31,050
  • 11
  • 59
  • 99
  • Okay, so those libraries not marked as exported are basically just hidden. They are there and will work if referenced but Eclipse just doesn't know about them and therefore throws an error? That makes sense I guess. – Mazen Aug 22 '17 at 06:45
  • @Mazen Yes, exactly. Eclipse offers a lightweight modularization via _required projects_ (with or without _access rules_) and _export_ flags at compile time, but not at run time. – howlger Aug 22 '17 at 08:15