如何使用相对路径将构建路径项添加到 Eclipse 3.5?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1427048/
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
How can I add build path items to Eclipse 3.5 using relative paths?
提问by basszero
Eclipse 3.5 added support for relative buildpath/classpath items, yet I cannot seem to find a graphical way to add relatively pathed items. The example in new and noteworthy (search the page for 'relative', about 40% of the way down)seems to indicate that I have to manually edit the .classpath file. Am I just missing something?
Eclipse 3.5 添加了对相对构建路径/类路径项的支持,但我似乎找不到添加相对路径项的图形方式。新的和值得注意的示例(在页面中搜索“relative”,大约向下的 40%)似乎表明我必须手动编辑 .classpath 文件。我只是错过了什么吗?
Edit 2015:Updated link as it had went away. To preserve the "new and noteworthy" indefinitely, here's a screenshot of the mentioned section.
2015 年编辑:更新链接,因为它已经消失。为了无限期地保留“新的和值得注意的”,这是上述部分的屏幕截图。
采纳答案by basszero
After evaluating all responses and tinkering with Eclipse I can see no way to do this without manually editing the .classpath file.
在评估所有响应并修改 Eclipse 后,如果不手动编辑 .classpath 文件,我无法做到这一点。
Marking this answer as accepted to indicate that there is no way to do this in Eclipse 3.5. Keep fingers crossed for Eclipse 3.6 or Eclipse 4.
将此答案标记为已接受以表明在 Eclipse 3.5 中无法执行此操作。请为 Eclipse 3.6 或 Eclipse 4 祈祷。
回答by Chris Thompson
The actual way to do this is to import the library into your workspace so,
执行此操作的实际方法是将库导入您的工作区,因此,
Right Click in Package Explorer -> Import -> File System -> Browse (to the directory containing your jars) -> check the boxes next to the jars you want -> Browse to the workspace folder you want to import to (probably your lib folder) -> Finish
在包资源管理器中右键单击 -> 导入 -> 文件系统 -> 浏览(到包含你的 jar 的目录) -> 选中你想要的 jar 旁边的框 -> 浏览到你想要导入的工作区文件夹(可能是你的 lib文件夹)-> 完成
Keep in mind this will copy the files into the lib folder so I've found that it helps keep things clean if you don't already have them in there. They will now show up in the package explorer under "lib." To add them to the classpath,
请记住,这会将文件复制到 lib 文件夹中,因此我发现如果您还没有将它们放在那里,它有助于保持清洁。它们现在将显示在“lib”下的包浏览器中。要将它们添加到类路径,
Right click on the project -> Build Path -> configure build path... -> Add JARs -> navigate to the given project's lib folder and select the appropriate JARs -> click ok -> click finish
右键单击项目 -> 构建路径 -> 配置构建路径... -> 添加 JAR -> 导航到给定项目的 lib 文件夹并选择适当的 JAR -> 单击确定 -> 单击完成
This adds them to the CP with relative locations.
这会将它们添加到具有相对位置的 CP。
If you need more help let me know
如果您需要更多帮助,请告诉我
回答by Mike Jones
I'm uing Helios (i.e. 3.6.x) and this is what I do to reference a lib (jar) outside of my project in a relative manner.
我正在使用 Helios(即 3.6.x),这就是我以相对方式在我的项目之外引用 lib(jar)的方法。
1) Right click project in project explorer -> Import -> Import. 2) Select File System (Next) Use the browse button to navigate to the folder (yes, it looks like a hard-path). Select the .jar(s) to include.
1) 在项目资源管理器中右键单击项目 -> 导入 -> 导入。2)选择文件系统(下一步)使用浏览按钮导航到文件夹(是的,它看起来像一个硬路径)。选择要包含的 .jar(s)。
I usually append "\lib" to the project name in the "Into Folder:" option.
我通常将“\lib”附加到“Into Folder:”选项中的项目名称。
Click "Advanced" and select the "Create Links in workspace" and I use the default options (both checked, and relative to PROJECT_LOC). 3) Click Finish
单击“高级”并选择“在工作区中创建链接”,我使用默认选项(都选中,并且相对于 PROJECT_LOC)。3)点击完成
Next, open up the project properties and go to Java Build Path Libraries tab and select "Add Jars..." and go to the \lib folder (from Step 2) and select the lib(s) that you need. On the Libraries tab now has "ProjectName/Lib" for the path of the lib(s).
接下来,打开项目属性并转到 Java Build Path Libraries 选项卡并选择“Add Jars...”并转到 \lib 文件夹(来自第 2 步)并选择您需要的库。在库选项卡上现在有“项目名称/库”作为库的路径。
The project explorer will display a lib folder with your libs with a special icon. If you look in your hard drive for the lib folder, there is nothing there. So it is referring to the libs in the external path, but including them as a "project" lib.
项目资源管理器将显示一个带有特殊图标的 lib 文件夹。如果您在硬盘驱动器中查找 lib 文件夹,则那里什么也没有。所以它指的是外部路径中的库,但将它们作为“项目”库包含在内。
Right click on the jar file in the project explorer and do properties. You should see the relative path goodness.
右键单击项目资源管理器中的 jar 文件并执行属性。您应该看到相对路径的优点。
回答by Jud
Simple. without all dialogs and menus.
简单的。没有所有的对话框和菜单。
In your .project file add the path to the real file, like this.
Mine is on ../libs/GoogleAdMobAdsSdkAndroid-4.1.1/GoogleAdMobAdsSdk-4.1.1.jar
so i changed to PARENT-1-PROJECT_LOC/libs/...
在您的 .project 文件中添加真实文件的路径,如下所示。我的是在 ../libs/GoogleAdMobAdsSdkAndroid-4.1.1/GoogleAdMobAdsSdk-4.1.1.jar
所以我改为 PARENT-1-PROJECT_LOC/libs/...
<linkedResources>
<link>
<name>libs/GoogleAdMobAdsSdk-4.1.1.jar</name>
<type>1</type>
<locationURI>PARENT-1-PROJECT_LOC/libs/GoogleAdMobAdsSdkAndroid-4.1.1/GoogleAdMobAdsSdk-4.1.1.jar</locationURI>
</link>
</linkedResources>
and in .classpath i use
在 .classpath 我使用
<classpathentry kind="lib" path="libs/GoogleAdMobAdsSdk-4.1.1.jar"/>
as the link to the lib
作为lib的链接
Eclipse links the resource to project and uses it without copping the file Just like Mike Jones answer above but without any dialogs
Eclipse 将资源链接到项目并使用它而不复制文件就像上面的 Mike Jones 回答一样,但没有任何对话框
Best for multiple apps
最适合多个应用程序
回答by Jud
This does not work!
这不起作用!
Editing the .classpath to include relative paths as per the New and Noteworthy example (path="../../lib/myjar.jar") isn't difficult, however it does not appear to work as described!
根据 New and Noteworthy 示例 (path="../../lib/myjar.jar") 编辑 .classpath 以包含相对路径并不困难,但它似乎不像描述的那样工作!
It seems to resolve relative to the Workspace and not the specific Project as specified, which is not much use. Has anyone else found the same problem or a solution to this?
它似乎是相对于工作区而不是指定的特定项目来解决的,这没什么用。有没有其他人发现同样的问题或解决方案?
回答by NickDK
I think you can do this graphically instead of editing .classpath. Depending on Eclipse version it's something like:
我认为您可以以图形方式执行此操作,而不是编辑 .classpath。根据 Eclipse 版本,它类似于:
Right-click project --> Properties --> Build Path --> Libraries (tab) --> Add Variable
右键单击项目--> 属性--> 构建路径--> 库(选项卡)--> 添加变量
Works in my current Eclipse with a Java project.. ;-)
在我当前的 Eclipse 中使用 Java 项目工作.. ;-)
回答by Simon Groenewolt
As far as I know you currently can only achieve this by editing the .classpath file. For this to be possible through pure 'button pushing' the browse dialogs popping up after selecting 'Add External JARs...' and 'Add External Class Folder...' would need something like a check-box to specify if you want to add the relative or the absolute path. Maybe that is not hard to add, but I haven't seen it yet.
据我所知,您目前只能通过编辑 .classpath 文件来实现此目的。为了通过纯“按钮推送”实现这一点,选择“添加外部 JAR...”和“添加外部类文件夹...”后弹出的浏览对话框需要类似于复选框的东西来指定您是否想要添加相对或绝对路径。也许这不难添加,但我还没有看到。
回答by Suraj Chandran
No. As of yet, it is not possible. But you will be seeing it soon. Keep checking the intergration builds.
不。到目前为止,这是不可能的。但你很快就会看到它。继续检查集成构建。
回答by vinnybad
I've done this by adding the libraries to my project. So, create a folder under your project called "jars" and put all dependent jars in there.
我通过将库添加到我的项目来完成此操作。因此,在您的项目下创建一个名为“jars”的文件夹,并将所有依赖的 jar 放在那里。
When you configure the build path afterward, everything will be relative.
之后配置构建路径时,一切都将是相对的。