The "Order and Export" tab in "Java Build Path"
Asked Answered
C

5

22

enter image description here

What's the use of "Order and Export" tab in "Java Build Path" dialog box? By the name 'order', I can guess that JRE System library is searched before Plug-in Dependencies, but why do we have 'Export' in Build Path ? And what's it for the button left side of the elements?

ADDED

It's the example that I borrowed from Eclipse distilled.

The orderes.webapp depends on orders, but it's likely to use the classes defined in ubl and catalog.

enter image description here

In such a case, orders can export catalog and ubl so that the packages that depends on it can use catalog and ubl.

enter image description here

And something more about "Order and Export".

  1. The check of the left side button modifies the .classpath file to add exported=true such as <classpathentry exported="true" kind="lib" path="lib/log4j-1.2.7.jar"/>.
  2. The src is always checked, and you can't uncheck it.

References

Connaught answered 18/12, 2012 at 22:35 Comment(0)
H
9

This tab seems to pull double duty (see bottom of this help page for small amount of detail).

On one hand, it functions as the order of resolution for resources used in the building of the project in question (the "Order" part). On the other, it also serves to define what parts of this build path are contributed to dependent projects' (those listing this project in the "projects" tab for their view of this preference panel) build paths (the "Export" part).

This latter function is why the checkboxes exist on the left hand side, as you ask (note that the '-' signs cannot be unchecked, as source files defined in this project cannot be deselected, as stated in help file). A dependent project that expects some resource from the contributing project will not compile/run if the contributing project doesn't export that resource.

EDIT: see this SO post for corroboration.

Hanleigh answered 18/12, 2012 at 23:4 Comment(0)
S
6

a very good example from Coderanch by Ilja Preuss

Say you have junit.jar in the build path of project A. Project B depends on project A.

Now you write a junit test in project B. If project A exports junit.jar, project B can use it at compile time - no more action necessary. If A doesn't export it, B doesn't know about it - you will have to explicitely put it into its build path, too.

Shluh answered 22/1, 2014 at 17:36 Comment(1)
Does it mean that if we do not export, twice the amount of RAM is needed? Or is it merely a visibility option?Burgle
G
2

Order and Export tab as your rightly guessed shows the order of libraries which will be included in your project build path.

Using the buttons up and down you can adjust your libraries order according to your project needs.

Gideon answered 18/12, 2012 at 22:50 Comment(0)
H
2

To answer your specific question, if this project were to be added as a dependency for another Java project, the order would be used to resolve classes and packages in this project when running the other project. Those classes and packages are said to be exported to/for the other running project's class path.

Honorary answered 18/12, 2012 at 22:53 Comment(0)
C
2

There is one case where-in I found this useful. I had to use a sun.* class of an IBM jar. This class was also present in local jre, but my requirement was to use IBM's class. But by default,the compiler would refer the local jdk class only. In the eclipse order and export tab, I moved the external jar ahead of the JRE lib. Now, the compiler would refer to the class from IBM jar instead of local JRE.

Cattycornered answered 9/3, 2013 at 11:34 Comment(2)
What happens if there are two duplicate classes in both packages, but you require one from each package?Altruistic
@Ryan I think that is allowed since the package names should be different. As long as you specify which, com.some.packageA.SomeObject.class !instanceof com.some.packageB.SomeObject.classVenality

© 2022 - 2024 — McMap. All rights reserved.