在 Eclipse 中设置不同的 Java 类路径
我得到了一个使用 build.xml 文件进行构建的应用程序。我对 Apache Ant 知之甚少,类路径似乎如下:
<!-- Classpath -->
<path id="development-classpath">
<fileset dir="${libs.dir}">
<include name="**/*.jar"/>
</fileset>
<pathelement location="."/>
<pathelement location="${classes.dir}"/>
<pathelement location="${configuration.dir}/langs/"/>
<pathelement location="${fits.dir}/xml/nlnz"/>
</path>
由于我想使用 Eclipse 自己的构建工具,我想在 Eclipse 中分配这些类路径变量,我对此没有太多经验。我该怎么做?
I have been given an application which uses a build.xml file for building purposes. I have very little knowledge of Apache Ant and the classpaths seems to be the following:
<!-- Classpath -->
<path id="development-classpath">
<fileset dir="${libs.dir}">
<include name="**/*.jar"/>
</fileset>
<pathelement location="."/>
<pathelement location="${classes.dir}"/>
<pathelement location="${configuration.dir}/langs/"/>
<pathelement location="${fits.dir}/xml/nlnz"/>
</path>
As I want to use Eclipse own building facilities I would like to assign these classpaths variable in Eclipse, which I don't have much experience with. How do I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
转到外部工具配置,选择 ant 构建,然后单击“属性”选项卡。您可能必须取消单击“使用全局属性...”。然后只需添加属性即可。这将允许您访问 Eclipse 中内置的变量,例如 ${project-loc},并且这些属性将可供 ant 使用,就像您已在 ant 文件本身中设置它们一样。
Go to your external tools configuration, select your ant build, and click on the Properties tab. You will probably have to un-click "Use global properties...". Then it is simply a matter of adding properties. This will allow you access to the variables built into Eclipse such as ${project-loc} and these properties will be available to ant as if you had set them in the ant file itself.
下面是配置 Eclipse 以模仿 ant 使用 build.xml 文件执行的操作的手动方法。这应该可以帮助您开始:
打开 Eclipse,打开
"Java"
透视图。右键单击该项目并选择“构建路径/配置构建路径”
。或者,单击“项目”
菜单,选择“属性”
,然后单击“Java 构建路径”
。单击“库”选项卡。您可以在此处告诉 Eclipse 构建项目所需的 jar 所在的位置。从 build.xml 片段中,第一个
""
指定您需要的所有 jar 都位于/libs
目录下(我是猜测${libs.dir}
对应于"libs"
但您可能需要仔细检查它应该在 build.xml 的顶部附近定义。因此,单击“添加 Jars...”
,导航到/libs
,突出显示目录中的所有 jar,然后单击“确定”
。第一个和第二个
标记告诉 ant 使用当前目录和类目录。默认情况下,Eclipse 应该已经处理了这个问题,但要仔细检查,请单击"Source"
选项卡(应该与“库”选项卡)。默认输出文件夹
显示 eclipse 将 java 代码编译为 .class 文件的位置。构建路径上的源文件夹显示了 Eclipse 应该尝试编译的所有源代码。最后,最后两个
标签告诉 ant 使用${configuration.dir}/langs
和${fits 下的一些资源/配置文件。 dir}/xml/nlnz
。您可以像添加罐子一样添加它们。单击“库”选项卡。然后选择“添加类文件夹”并突出显示“langs”和“nlnz”文件夹。希望这能让您深入了解 Eclipse 在哪里查找 jar 依赖项、类文件和资源。
说了这么多,当您越来越熟悉 Eclipse 和构建工具时,您可能会发现这可能不是最好的方法,因为 build.xml 和 eclipse 配置很容易不同步。有多种方法可以告诉 eclipse 使用 ant build.xml 文件进行构建(查看
File->New Project->Java Project form Existing Ant Buildfile
)。还有一些方法可以在 Eclipse 中运行 ant 目标(查看 Window -> show view -> ant)。Here's the manual way to configure Eclipse to mimic what ant will do using the build.xml file. This should get you started:
Open Eclipse, open the
"Java"
Perspective. Right click the project and choose"Build Path / Configure Build Path"
. Alternatively click"Project"
Menu, and choose"properties"
, then click"Java Build Path"
. Click the Libraries Tab. This is where you tell Eclipse where the jars needed build your project are located.From the build.xml snippet, the first
"<fileset>"
specifies that all the jars you need are under the<project>/libs
directory (I'm guessing that${libs.dir}
corresponds to"libs"
but you might want to double check. It should be defined near the top of build.xml). So click,"Add Jars..."
, navigate into<project>/libs
, highlight all the jars inside the directory and then click"Ok"
.The first and second
<pathelement>
tags are telling ant to use the current directory and the classes directory. Eclipse should already take care of this by default, but to double check, click on the"Source"
Tab (should be in the same"Java Build Path"
dialog as the "Libraries" tab). Thedefault output folder
shows where eclipse will compile java code to .class files. TheSource folders on build path
shows where all your source code is that Eclipse should try to compile.Finally, The last two
<pathelement>
tags tell ant to use some resource/config files under${configuration.dir}/langs
and${fits.dir}/xml/nlnz
. You can add these similar to the way you added the jars. Click"Libraries"
Tab. Then choose"Add Class Folder"
and highlight both the"langs"
and"nlnz"
folders.Hope this give you some insight into where Eclipse looks for jar dependencies, class files and resources.
Having said all this, as you become more familiar with Eclipse and build tools, you'll probably discover that this probably isn't the best way to go because it's very easy for the build.xml and eclipse configuration to get out of sync. There are ways to tell eclipse to build using an ant build.xml file (check out
File->New Project->Java Project form Existing Ant Buildfile
). And there are also ways to run ant targets from within Eclipse (check outWindow -> show view -> ant
).可能您需要将 build.properties 文件放在与 build.xml 相同的路径中。
此 build.properties 看起来与此类似:
这将允许在 Eclipse 内部和外部使用这些配置值运行 ant 脚本。
Probably you need to put build.properties files at same path which build.xml is.
This build.properties will looks like similar to this:
This will allow to run your ant script with these configuration values inside and outside Eclipse.