eclipse “Java Build Path”中的“Order and Export”选项卡

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13942628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 21:28:38  来源:igfitidea点击:

The "Order and Export" tab in "Java Build Path"

eclipsebuild

提问by prosseek

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?

“Java Build Path”对话框中的“Order and Export”选项卡有什么用?通过名称'order',我可以猜测JRE System library是在Plug-in Dependencies之前搜索的,但是为什么我们在Build Path中有'Export'?元素左侧的按钮是什么?

ADDED

添加

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

这是我从Eclipse distilled借来的例子。

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

orderes.webapp 依赖于订单,但它很可能使用 ubl 和目录中定义的类。

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.

在这种情况下,orders 可以导出catalog 和ubl,这样依赖它的包就可以使用catalog 和ubl。

enter image description here

在此处输入图片说明

And something more about "Order and Export".

还有更多关于“订购和出口”的信息。

  1. The check of the left side button modifies the .classpathfile to add exported=truesuch 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.
  1. 左侧按钮的勾选修改了.classpath要添加的文件,exported=true例如<classpathentry exported="true" kind="lib" path="lib/log4j-1.2.7.jar"/>.
  2. src 始终处于选中状态,您无法取消选中它。

References

参考

采纳答案by Brian Henry

This tab seems to pull double duty (see bottom of this help pagefor 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 postfor corroboration.

编辑:请参阅此 SO 帖子以供证实。

回答by cherit

a very good example from Coderanchby Ilja Preuss

Ilja Preuss来自Coderanch的一个很好的例子

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.

假设您在项目 A 的构建路径中有 junit.jar。项目 B 依赖于项目 A。

现在您在项目 B 中编写一个 junit 测试。如果项目 A 导出 junit.jar,项目 B 可以在编译时使用它 - 无需更多操作。如果 A 不导出它,B 不知道它 - 您也必须明确地将它放入它的构建路径中。

回答by user2151189

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.

在一种情况下,我发现这很有用。我不得不使用 IBM jar 的 sun.* 类。这个类也存在于本地 jre 中,但我的要求是使用 IBM 的类。但默认情况下,编译器只会引用本地 jdk 类。在 eclipse order and export 选项卡中,我将外部 jar 移到 JRE lib 之前。现在,编译器将引用 IBM jar 中的类,而不是本地 JRE。

回答by Sajan Chandran

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

Order and Export您正确猜测的选项卡显示了将包含在您的项目构建路径中的库的顺序。

Using the buttons upand downyou can adjust your libraries order according to your project needs.

使用按钮updown您可以根据项目需要调整库顺序。

回答by Chris Gerken

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.

为了回答您的具体问题,如果要将此项目添加为另一个 Java 项目的依赖项,则在运行另一个项目时将使用该顺序来解析该项目中的类和包。据说这些类和包被导出到/用于其他正在运行的项目的类路径。