如何使用相对路径将构建路径项添加到 Eclipse 3.5?

发布于 2024-08-04 17:36:50 字数 477 浏览 7 评论 0原文

Eclipse 3.5 添加了对相对构建路径/类路径项目的支持,但我似乎找不到添加相对路径项目的图形方式。 新的且值得注意的示例(搜索“相对”页面,大约向下 40%) 似乎表明我必须手动编辑 .classpath 文件。我只是错过了什么吗?

2015 年编辑:更新了已消失的链接。为了无限期地保留“新的和值得注意的”,这里是上述部分的屏幕截图。

输入图片此处描述

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?

Edit 2015: Updated link as it had went away. To preserve the "new and noteworthy" indefinitely, here's a screenshot of the mentioned section.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

情定在深秋 2024-08-11 17:36:50

执行此操作的实际方法是将库导入到您的工作区中,因此,

在 Package Explorer 中右键单击 ->导入->文件系统->浏览(到包含 jar 的目录)->选中您想要的罐子旁边的复选框 ->浏览到您要导入的工作区文件夹(可能是您的 lib 文件夹)->完成

请记住,这会将文件复制到 lib 文件夹中,因此我发现如果您还没有将它们放入其中,它有助于保持文件干净。它们现在将显示在包资源管理器的“lib”下。要将它们添加到类路径中,

请右键单击项目 ->构建路径->配置构建路径...->添加 JAR ->导航到给定项目的 lib 文件夹并选择适当的 JAR ->点击确定->单击完成

这会将它们添加到具有相对位置的 CP。

如果您需要更多帮助,请告诉我

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

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,

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

This adds them to the CP with relative locations.

If you need more help let me know

往日情怀 2024-08-11 17:36:50

我正在使用 Helios(即 3.6.x),这就是我以相对方式引用项目外部的 lib(jar)的方法。

1)在项目资源管理器中右键单击项目->导入->进口。
2) 选择文件系统(下一步) 使用浏览按钮导航到文件夹(是的,它看起来像硬路径)。选择要包含的 .jar。

我通常将“\lib”附加到“进入文件夹:”选项中的项目名称。

单击“高级”并选择“在工作区中创建链接”,我使用默认选项(均已选中,且相对于 PROJECT_LOC)。
3) 单击 Finish

Next,打开项目属性并转到 Java Build Path Libraries 选项卡并选择“Add Jars...”,然后转到 \lib 文件夹(来自步骤 2)并选择您需要的库。现在,“库”选项卡上的库路径为“ProjectName/Lib”。

项目资源管理器将显示一个 lib 文件夹,其中包含带有特殊图标的库。如果您在硬盘驱动器中查找 lib 文件夹,那里什么也没有。因此,它引用外部路径中的库,但将它们包含为“项目”库。

右键单击项目资源管理器中的 jar 文件并执行属性操作。您应该看到相对路径的好处。

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.

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.

I usually append "\lib" to the project name in the "Into Folder:" option.

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

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).

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.

Right click on the jar file in the project explorer and do properties. You should see the relative path goodness.

心是晴朗的。 2024-08-11 17:36:50

简单的。没有所有对话框和菜单。

在您的 .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>

并在 .classpath 中用作

<classpathentry kind="lib" path="libs/GoogleAdMobAdsSdk-4.1.1.jar"/>

lib Eclipse 的链接

,将资源链接到项目并使用它而不复制文件
就像迈克·琼斯上面的回答一样,但没有任何对话框

最适合多个应用程序

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/...

<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

<classpathentry kind="lib" path="libs/GoogleAdMobAdsSdk-4.1.1.jar"/>

as the link to the lib

Eclipse links the resource to project and uses it without copping the file
Just like Mike Jones answer above but without any dialogs

Best for multiple apps

橪书 2024-08-11 17:36:50

这不行!

编辑 .classpath 以包含新的且值得注意的示例 (path="../../lib/myjar.jar") 中的相对路径并不困难,但它似乎并不像描述的那样工作!

它似乎是相对于工作空间而不是指定的特定项目来解析的,这没有多大用处。还有其他人发现了同样的问题或解决方案吗?

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!

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?

时光匆匆的小流年 2024-08-11 17:36:50

我认为您可以以图形方式完成此操作,而不是编辑 .classpath。根据 Eclipse 版本,它类似于:

右键单击项目 -->属性-->构建路径 -->库(选项卡)--> 添加变量工作..;-)

在我当前的 Eclipse 中使用 Java 项目

I think you can do this graphically instead of editing .classpath. Depending on Eclipse version it's something like:

Right-click project --> Properties --> Build Path --> Libraries (tab) --> Add Variable

Works in my current Eclipse with a Java project.. ;-)

烟酒忠诚 2024-08-11 17:36:50

在评估所有响应并修改 Eclipse 之后,我发现如果不手动编辑 .classpath 文件,就没有办法做到这一点。

将此答案标记为已接受,表明在 Eclipse 3.5 中无法执行此操作。请为 Eclipse 3.6 或 Eclipse 4 祈祷。

After evaluating all responses and tinkering with Eclipse I can see no way to do this without manually editing the .classpath file.

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.

二智少女 2024-08-11 17:36:50

据我所知,目前只能通过编辑 .classpath 文件来实现此目的。为了通过纯粹的“按钮按下”来实现这一点,选择“添加外部 JAR...”和“添加外部类文件夹...”后弹出的浏览对话框将需要类似复选框的内容来指定您是否想要添加相对或绝对路径。也许这并不难添加,但我还没有看到。

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.

离笑几人歌 2024-08-11 17:36:50

不,目前还不可能。但你很快就会看到它。继续检查集成版本。

No. As of yet, it is not possible. But you will be seeing it soon. Keep checking the intergration builds.

毁我热情 2024-08-11 17:36:50

我通过将库添加到我的项目中来完成此操作。因此,在您的项目下创建一个名为“jars”的文件夹,并将所有依赖的 jar 放入其中。

当您随后配置构建路径时,一切都将是相对的。

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.

When you configure the build path afterward, everything will be relative.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文