views:

166

answers:

3

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?

+1  A: 

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.

rancidfishbreath
A: 

Probably you need to put build.properties files at same path which build.xml is.

This build.properties will looks like similar to this:

libs.dir=path_where_libs_are
classes.dir=path_where_classes_are
configuration.dir=etc
fits.dir=etc

This will allow to run your ant script with these configuration values inside and outside Eclipse.

SourceRebels
A: 

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). The default output folder shows where eclipse will compile java code to .class files. The Source 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 out Window -> show view -> ant).

Dave Paroulek