0

I have an ant script that does the tipically: clean, compile, jar, javadocs, etc. I also have 3 projects in Eclipse: a library and 2 projects to test it.

In the build path of this 2 test projects I've defined as external jar the library jar located in the library project.

The library jar has its version in the jar name, i.e. library-0.1.jar. In the ant script I have a property with the version of the library:

<property name="project_version" value="0.1"/>

So to change the version I modify this property and run the script again. As you may deduce this generates a dependency error in the 2 other projects because they will still be pointing to an old file library-0.1.jar.

How can I change automatically the build path of that 2 other projects in Eclipse? Apache ant can do this with a specific tag?

Thanks.

3 Answers 3

4

Refer to the version with a variable in all your build files, e.g.

<include name="my-${version}.jar"/>

Now when you execute your builds, you can execute with explict version to match what you require, e.g.

ant -Dversion=1.3

Alternatively, you could load the same properties file in each of your build scripts to load the version property

<property file="version.properties">

Note that if you go with the latter you should remove the property declaration (from you post above) which sets the value explicitly. Either that or load the properties file first. ....

2
  • I've created a version.properties file with the version variable and used in the library build script (with property, not properties) but I have problems including the jar in the test projects. Does the "include" tag add the jar to build path? Apr 15, 2011 at 13:11
  • 1
    Yes, I was just guessing that you would have build classpath to your jar in the build file using <classpath><fileset><include>, but maybe you do it differently. In any case, where you refer to the library jar in the buildfiles of the dependent projects, do so using the variable. Apr 15, 2011 at 14:05
2

Use sed, e.g. (not tested):

version=2
sed s/value="\d+"/value="$version"/g build.xml
0

EDIT: Using the method below you will be able to compile using Ant, but eclipse will show you a dependency error in the project explorer because you don't have defined any external jar in the build path panel. To solve this you have to edit the .classpath file that you will see in the project root and add the following line:

<classpathentry kind="lib" path="../Library/bin"/>

Where Library is the folder for Library project and bin the folder for classes.




SOLVED:

I have to write an ant script for the 2 other projects and set the classpath with the script, not with eclipse IDE:

<path id="build-classpath">
    <fileset dir="${dist}">
        <include name="${project_name}-${project_version}.jar"/>
    </fileset>
</path>

${dist} is the folder where is the jar library it's something like: "../Library/dist", where Library is the name of the project.
${project_name} and ${project_version} are loaded from a version.properties file that, again, is stored in "../Library":

<property file="..Library/version.properties"/>

The file version.properties just contains:

project_name=LibraryName
project_version=0.1

Then, to add the classpath when compiling...

<target name="compile" depends="clean, makedir">
    <javac srcdir="${src}" destdir="${bin}">
        <classpath refid="build-classpath"/>
    </javac>
</target>

The refid value is the path id defined previously.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.