Eclipse 类路径中的嵌套文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/344777/
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
Nested Folders in Eclipse Classpath
提问by Ryan Thames
I'm trying to add two folders to my eclipse project's classpath, let's say Folder A and Folder B. B is inside A. Whenever I add A to the classpath
我正在尝试将两个文件夹添加到我的 eclipse 项目的类路径中,假设文件夹 A 和文件夹 B。B 在 A 中。每当我将 A 添加到类路径时
<classpathentry kind="lib" path="/A"/>
it works just fine, but I need to be able to access the files in B as well. Whenever I try to add
它工作得很好,但我也需要能够访问 B 中的文件。每当我尝试添加
<classpathentry kind="lib" path="/A/B"/>
to the classpath, it says
到类路径,它说
Cannot nest 'A/B inside library A'
不能在库 A 中嵌套“A/B”
I'm a newbie when it comes to editing the classpath, so I'm wondering, is there is anyway to add a folder in the eclipse classpath that is nested in another folder that is also in the eclipse classpath?
在编辑类路径时,我是新手,所以我想知道,是否可以在 eclipse 类路径中添加一个文件夹,该文件夹嵌套在另一个也在 eclipse 类路径中的文件夹中?
回答by Uri
I don't think you can (or should be) allowed to do that, and it's not really an Eclipse issue AFAIK
我认为您不能(或应该)这样做,这并不是 Eclipse 问题 AFAIK
Any individual classpath is a root under which the JVM starts looking for classes using the standard package notation
任何单独的类路径都是一个根,JVM 开始在该根下使用标准包表示法查找类
So let's say that your program has a class X in the default package, and a b.X class in the b package. If the default package root is /a, then your package b would be in /a/b
所以假设你的程序在默认包中有一个类 X,在 b 包中有一个 bX 类。如果默认包根目录是 /a,那么你的包 b 将在 /a/b 中
If you had one classpath root pointing to /a and one classpath root pointing to /a/b, and now you asked for class X, then one could interpret your request as X in the default package (since there is a root at A), but also as class X in the default package relative to the path /a/b, but that is the class b.X
如果您有一个指向 /a 的类路径根和一个指向 /a/b 的类路径根,并且现在您要求类 X,则可以将您的请求解释为默认包中的 X(因为 A 处有一个根) ,但也作为相对于路径 /a/b 的默认包中的类 X,但那是类 bX
So to prevent these things from happening, you're not allowed to have classpath roots that are nested.
因此,为了防止这些事情发生,不允许嵌套类路径根。
回答by michaelliu
Try to do this, works for me on eclipse Indigo.
尝试这样做,在 eclipse Indigo 上对我有用。
<classpathentry kind="lib" path="/A" excluding="B/"/>