Ant / Eclipse complains about artifact:dependencies - eclipse

I need to use XML to JSON lib in my war.
I followed a tutorial explaining that dependencies are required in the project.
But when I add the following in my ant build.xml (the file used to create the war), Eclipse complains about the artifact:dependencies, seems like it does not like the :.I have the following error message:
The prefix artifact for element artifact:dependencies is not bound...
<artifact:dependencies filesetId="dependency.fileset"
sourcesFilesetId="sources.dependency.fileset"
javadocFilesetId="javadoc.dependency.fileset"
versionsId="dependency.versions">
<!-- DEPENCIES GO HERE -->
</artifact:dependencies>
Any idea ?
UPDATE
I have the same problem trying to define an in-memory pom with:
<artifact:pom id="mypom" groupId="org.acme" artifactId="project1" version="1.0">
<dependency groupId="junit" artifactId="junit" version="4.1"/>
<dependency groupId="org.codehaus.plexus" artifactId="plexus-utils" version="1.5.5"/>
<license name="apache" url="http://www.apache.org"/>
</artifact:pom>
The prefix artifact for element artifact:pom is not bound...
UPDATE 2
I installed maven-ant jar in ant/lib and change the build.xml so it contains the definition of the artifact stuff but I have an error message while running it.
<project name="test" default="install" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<artifact:dependencies pathId="dependency.classpath">
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.3</version>
<type>jar</type>
<classifier>jdk15</classifier>
<scope>compile</scope>
</dependency>
...
The error message Eclipse gave is:
BUILD FAILED
D:\J2EE\workspace\Test\build.xml:3: Problem: failed to create task or type antlib:org.apache.maven.artifact.ant:dependencies
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet
This appears to be an antlib declaration.
Action: Check that the implementing library exists in one of:
-D:\eclipse\plugins\org.apache.ant_1.8.2.v20110505-1300\lib
-C:\Documents and Settings\luc\.ant\lib
-a directory added on the command line with the -lib argument
The maven-ant jar does exist in -D:\eclipse\plugins\org.apache.ant_1.8.2.v20110505-1300\lib
UPDATE 3
This is the build.xml file I'm using.
<!--
<project name="Monitoring" default="install" xmlns:artifact="urn:maven-artifact-ant" xmlns:test="urn:test-tasks">
-->
<project name="Monitoring" default="install" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<!-- project-specific variables -->
<property environment="env" />
<property name="project_home" value="D:\J2EE\workspace\Monitoring"/>
<property name="webapp.dir" value="${project_home}/target" />
<property name="jboss.dir" value="D:\J2EE\jboss\standalone\deployments" />
<property name="package.name" value="monitoring.war" />
<property name="lib.dir" value="${project_home}/lib" />
<property name="src.dir" value="${project_home}/src" />
<property name="resources.dir" value="${project_home}/resources" />
<property name="dest.dir" value="${project_home}/target" />
<property name="package.file" value="${dest.dir}/${package.name}" />
<!-- put everything in a temp folder with the right structure during the build -->
<property name="temp.dir" value="${project_home}/temp" />
<property name="temp.dir.web-inf" value="${temp.dir}/WEB-INF" />
<property name="temp.dir.lib" value="${temp.dir.web-inf}/lib" />
<property name="temp.dir.classes" value="${temp.dir.web-inf}/classes" />
<property name="temp.dir.meta-inf" value="${temp.dir}/META-INF" />
<path id="build.class.path">
<fileset dir="${env.JAVA_HOME}/lib">
<include name="**/*.jar" />
</fileset>
<fileset dir="D:\ant\lib">
<include name="**/*.jar" />
</fileset>
</path>
<target name="deps">
<artifact:dependencies pathId="dependency.classpath">
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.3</version>
<type>jar</type>
<classifier>jdk15</classifier>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>xom</groupId>
<artifactId>xom</artifactId>
<version>1.1</version>
</dependency>
</artifact:dependencies>
</target>
<target name="clean" depends="deps">
<delete>
<fileset dir="${dest.dir}" includes="**/*"/>
</delete>
<delete dir="${temp.dir}" />
<delete dir="${temp.dir.classes}" />
<delete dir="${temp.dir.meta-inf}" />
<delete dir="${temp.dir.web-inf}" />
</target>
<target name="prepare" depends="clean">
<mkdir dir="${dest.dir}" />
<mkdir dir="${temp.dir}" />
<mkdir dir="${temp.dir.lib}" />
<mkdir dir="${temp.dir.meta-inf}" />
<mkdir dir="${temp.dir.web-inf}" />
<mkdir dir="${temp.dir.classes}" />
</target>
<!-- COMPILE -->
<target name="compile" depends="prepare">
<echo>=== COMPILE ===</echo>
<echo>Compiling ${src.dir} files ...</echo>
<javac debug="on" srcdir="${src.dir}" destdir="${temp.dir.classes}" includes="**/*" includeantruntime="false">
<classpath refid="build.class.path" />
<classpath refid="dependency.classpath" />
</javac>
</target>
<!-- PACKAGE -->
<target name="package" depends="compile">
<echo>=== PACKAGE ===</echo>
<!-- copy the config files -->
<copy file="${resources.dir}/web.xml" tofile="${temp.dir.web-inf}/web.xml" overwrite="true" />
<copy file="${resources.dir}/manifest.mf" tofile="${temp.dir.meta-inf}/manifest.mf" overwrite="true" />
<copy todir="${temp.dir.classes}">
<fileset dir="${src.dir}">
<include name="**/*.xml"/>
<include name="**/*.xsl"/>
</fileset>
</copy>
<!-- the ant war task. with all resources in place, create the war file -->
<war destfile="${package.file}" webxml="${temp.dir.web-inf}/web.xml" basedir="${temp.dir}">
<lib dir="${lib.dir}" />
<classes dir="${temp.dir.classes}" />
</war>
</target>
<!-- INSTALL -->
<target name="install" depends="package">
<echo>=== INSTALL ===</echo>
<copy file="${package.file}" tofile="${webapp.dir}/${package.name}" overwrite="true" />
<copy file="${package.file}" tofile="${jboss.dir}/${package.name}" overwrite="true" />
</target>
</project>
It was working well before I added all the dependencies stuff... still cannot find out the pb here. Any help would be very welcome.

It looks like you're making use of Maven Ant Tasks. To do this you'll need a copy of the jar from the download area here.
Once (or if) you've got that, you'll need to modify your buildfile to use it.
The main things that are needed are to define the artifact namespace, and add the typedef for the ant-lib:
<project name="foo" default="foo" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<path id="maven-ant-tasks.classpath" path="lib/maven-ant-tasks-2.1.3.jar" />
<typedef resource="org/apache/maven/artifact/ant/antlib.xml"
uri="antlib:org.apache.maven.artifact.ant"
classpathref="maven-ant-tasks.classpath" />

I had the same error message but the cause was different.
Going to Window -> Preferences -> Ant -> Runtime and setting Ant Home solved my problem.
So for anyone that above solution doesn't work, check if "Ant Home" is pointing to the right direction

Related

Missing output files after running Ant script from Eclipse

I have a simple web application developed in the Eclipse Luna. The directory structure of the application is like:
Project name is SchoolSchedule.
Under the project name, there are Java Resources, build, WebContent folders, and the build.xml file.
Under Java Resources, it is the "src" folder and my Java code package name is under the "src" folder.
Under the WebContent, there are META-INF, WEB-INF and my jsp files
Under the WEB-INF, there are web.xml file and the "lib" directory.
The build.xml is at the project root. This web application runs successfully and produces expected results.
I created an Ant script to compile, build a WAR file, and deploy the WAR. But, even the basic task does not work. I right click on the build.xml --> run as ... --> Ant build. In the console, I can see all the echo messages and no error. However, I do not see any new directories created (I "refresh" the project.). No "class" files compiled from the Java code and not to mention build and deploy those tasks.
There is something I did not get it right. Please help. Here is my Ant script:
<?xml version="1.0" encoding="UTF-8"?>
<project name="AntWarWebApp" basedir="." >
<echo>Define properties</echo>
<property name="name" value="SchoolSchedule"/>
<property name="src" location="src"/>
<property name="web" location="WebContent"/>
<property name="build" location="build"/>
<property name="classDir" location="${build}/src"/>
<property name="distDir" location="${build}/dist"/>
<property name="warDir" location="${build}/war"/>
<property name="tomcat.webapps" value="C:\apache-tomcat-7.0.70\webapps" />
<echo>time stamp</echo>
<tstamp prefix="build-info">
<format property="current-date" pattern="d-MMMM-yyyy" locale="en" />
<format property="current-time" pattern="hh:mm:ss a z" locale="en" />
<format property="year-month-day" pattern="yyyy-MM-dd" locale="en" />
</tstamp>
<echo>clean up previous build directories</echo>
<target name="clean" description="Delete old build directories">
<delete dir="${distDir}"/>
<delete dir="${warDir}"/>
<delete dir="${classDir}"/>
</target>
<echo>create directories</echo>
<target name="init" depends="clean">
<mkdir dir="${build}"/>
<mkdir dir="${classDir}"/>
<mkdir dir="${warDir}"/>
<mkdir dir="${distDir}"/>
<mkdir dir="${warDir}/WEB-INF"/>
<mkdir dir="${warDir}/WEB-INF/classes"/>
</target>
<echo>start compiling</echo>
<target name="compile" depends="clean, init" description="Compile main
source tree java files">
<javac srcdir="${src}" destdir="${classDir}" />
<classpath>
<fileset dir="${basedir}/WebContent/WEB-INF/lib">
<include name="*" />
</fileset>
</classpath>
</target>
<echo>start building WAR file</echo>
<target name="buildwar" depends="clean, init, compile">
<war basedir="${wardir}" destfile="${distDir}/${name}.war"
webxml="${wardir}/WEB-INF/web.xml">
<webinf dir="${wardir}/WEB-INF/">
<include name="**/*.jar" />
</webinf>
<manifest>
<attribute name="Built-On" value="${build-info.current-date}" />
<attribute name="Built-At" value="${build-info.current-time}" />
</manifest>
</war>
</target>
<echo>end building WAR file</echo>
<target name="deploy" depends="init, compile, buildwar" description="Deploy application">
<delete dir="${tomcat.webapps}/*.war" />
<echo>copy WAR file to Tomcat deploy directory</echo>
<copy file="${distdir}/*.war" todir="${tomcat.webapps}" />
</target>
</project>
Aren't you supposed to have some kind of top-level element
<project>
....
</project>
around all this?

How to build and deploy adapter with single ANT script Worklight 6.1

At 6.1 the ant jar was split into two jars: worklight-ant-builder.jar and worklight-ant-deployer.jar. I can run the build or the deploy tasks by themselves but I have to change the fileset. I want to run the build adapter and deploy adapter out of a single ant script.
I've tried a few ways to include both jars in the taskdef fileset:
include name="*.jar"
or
filename name="*.jar"
or
include name="worklight-ant-builder.jar"
include name="worklight-ant-deployer.jar"
Its almost like the tasks won't accept multiple jars. The build always works, but the deploy only when the deployer.jar is "include name="worklight-ant-deployer.jar" by itself.
<taskdef resource="com/worklight/ant/defaults.properties">
<classpath>
<fileset dir="${worklight.server.install.dir}/WorklightServer">
<include name="*.jar"/>
<!-- <filename name="*.jar"/> -->
<!-- <include name="worklight-ant-builder.jar"/> -->
<!-- <include name="worklight-ant-deployer.jar"/> -->
</fileset>
</classpath>
</taskdef>
I understand the multi-script answer but I think I shouldn't have to do that. This is my full script:
<?xml version="1.0" encoding="UTF-8"?>
<project name="BuildDeployAdapter" basedir="." default="help">
<property name="worklight.server.install.dir" value="C:/IBM/Worklight61/"/>
<property name="adapter-source-files-folder" value="C:/Worklight/workspaces/base61p/HelloWorklight/adapters/HTTPAdapter"/>
<property name="destination-folder" value="C:/Worklight/workspaces/base61p/HelloWorklight/binANT"/>
<property name="myAdapter.adapter" value="${destination-folder}/HTTPAdapter.adapter"/>
<property name="http.server.port.context" value="http://mydomain:9080/worklight"/>
<taskdef resource="com/worklight/ant/defaults.properties">
<classpath>
<fileset dir="${worklight.server.install.dir}/WorklightServer">
<include name="*.jar"/>
<!-- <filename name="*.jar"/> -->
<!-- <include name="worklight-ant-builder.jar"/> -->
<!-- <include name="worklight-ant-deployer.jar"/> -->
</fileset>
</classpath>
</taskdef>
<target name="buildAdapter">
<adapter-builder
folder="${adapter-source-files-folder}"
destinationfolder="${destination-folder}"/>
</target>
<target name="deployAdapter">
<adapter-deployer deployable="${myAdapter.adapter}"
worklightserverhost="${http.server.port.context}"
userName="username" password="password" />
</target>
</project>
Right now I have to switch the included jar for each task, when I want to use the masked include - either include name=".jar" or filename name=".jar". This seems to be a limititation on the specific task not accepting more than one jar. Am I off base here?
Given the information you provided, it seems that a solution could be to create a separate script that would invoke the build and deploy scripts in sequence, like this:
<project name="Adapter Stuff" default="do.all" basedir=".">
<target name="do.all">
<ant antfile="path/to/worklight-build-adapter.xml"
target="build-target" inheritall="false"/>
<ant antfile="path/to/worklight-deploy-adapter.xml"
target="deploy-target" inheritall="false"/>
</target>
</project>

Eclipse with Java EE (EJB), ANT and Jenkins / Hudson

My Goal is to get a Enterprise Java Application to be built on Jenkins. The Application consists of 4 Projects (Client-Interfaces, Webapplcation (incl. Faces), EJB Application (incl. JPA), EAR-Container-Project).
When Eclipse deploys this projects to a glassfish server, it assembles the Webapplication (war-file), the Client-Interfaces (jar-file) and the EJB-Interfaces (jar-file) into one ear-File.
Now, if I want to use continous integration I need to achieve the same on the CI-Server jenkins.
My first idea was to solve this with ant, so I used the Export-Function of Eclipse and generated build-Files for the projects.
The Problem is that the generated Build-Files refer to the Java EE Libraries (such as Glassfish-Runtime, JPA-Library, etc) which are outside of the project directory. There are about 30 libraries.
This implies that I cannot use the file on jenkins, because this libraries are missing. Of course I can copy these, but I don't think this is how it should be done.
So, what is the best way to get the Java EE Enterprise Application to be built on the CI Server? Do I have to write the ANT-Script all by myself and copy the libraries into the project? Or am I Missing something obvious?
Since I did not found anything that suited for me, I wrote an ant script that covered my needs on my own.
Here is my solution if this helps anyone in the future:
`
<project basedir="." default="build" name="Project">
<available property="glassfishdir" value="/opt/glassfish3/glassfish/modules"
file="/opt/glassfish3/glassfish/modules" type="dir" />
<!-- ########### Property Declarations ################################################################################################################### -->
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.6"/>
<property name="source" value="1.6"/>
<property name="builddir" value="build" />
<property name="outputartifacts" value="out" />
<property name="web.name" value="ProjectWeb" />
<property name="web.projectpath" value="ProjectWeb"/>
<property name="web.src" value="${web.projectpath}/src" />
<property name="web.builddir" value="${builddir}/web" />
<property name="web.builddir.classes" value="${web.builddir}/WEB-INF/classes"/>
<property name="ejb.name" value="ProjectEJB" />
<property name="ejb.projectpath" value="ProjectEJB"/>
<property name="ejb.src" value="${ejb.projectpath}/src"/>
<property name="ejb.builddir" value="${builddir}/ejb" />
<property name="ejb.builddir.classes" value="${ejb.builddir}/classes" />
<property name="ejbclient.name" value="ProjectEJBClient" />
<property name="ejbclient.projectpath" value="ProjectEJBClient"/>
<property name="ejbclient.src" value="${ejbclient.projectpath}/src"/>
<property name="ejbclient.builddir" value="${builddir}/ejbclient" />
<property name="ejbclient.builddir.classes" value="${ejbclient.builddir}/classes"/>
<property name="ear.name" value="ProjectApplication" />
<property name="ear.dir" value="ProjectEAR" />
<!-- ########### Main Targets ################################################################################################################### -->
<target name="build" depends="create-ear">
</target>
<target name="clean-build">
<antcall target="clean" />
<antcall target="build" />
</target>
<target name="clean">
<delete dir="${builddir}"/>
<delete dir="${outputartifacts}"/>
</target>
<target name="init">
<mkdir dir="${outputartifacts}" />
</target>
<!-- ########### EJB App ################################################################################################################### -->
<target name="init-ejb" depends="init">
<mkdir dir="${ejb.builddir}" />
<copy includeemptydirs="false" todir="${ejb.builddir.classes}">
<fileset dir="${ejb.src}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="build-ejb" depends="init-ejb">
<javac debug="true" debuglevel="${debuglevel}" destdir="${ejb.builddir.classes}" includeantruntime="false" source="${source}" target="${target}">
<src path="${ejb.src}"/>
<classpath>
<fileset dir="${glassfishdir}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${outputartifacts}">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<!-- ########### WEB ################################################################################################################### -->
<target name="init-web" depends="init">
<mkdir dir="${web.builddir.classes}"/>
<copy includeemptydirs="false" todir="${web.builddir}">
<fileset dir="${web.projectpath}/WebContent">
</fileset>
</copy>
<copy includeemptydirs="false" todir="${web.builddir.classes}">
<fileset dir="${web.src}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target depends="init-web,create-ejb-client" name="build-web">
<javac debug="true" debuglevel="${debuglevel}" destdir="${web.builddir.classes}" includeantruntime="false" source="${source}" target="${target}">
<src path="${web.src}"/>
<classpath>
<fileset dir="${glassfishdir}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="out/">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<!-- ############## EJB CLIENT ################################################################################################################ -->
<target name="init-ejb-client" depends="init">
<mkdir dir="${ejbclient.builddir}"/>
<copy includeemptydirs="false" todir="${ejbclient.builddir.classes}">
<fileset dir="${ejbclient.src}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target depends="init-ejb-client" name="build-ejb-client">
<javac debug="true" debuglevel="${debuglevel}" destdir="${ejbclient.builddir.classes}" includeantruntime="false" source="${source}" target="${target}">
<src path="${ejbclient.src}"/>
<classpath>
<fileset dir="${glassfishdir}">
<include name="**/*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<!-- ############ CREATE ARCHIVES################################################################################################################## -->
<target name="create-web" depends="build-web">
<war destfile="${outputartifacts}/${web.name}.war" basedir="${web.builddir}" webxml="${web.projectpath}/WebContent/WEB-INF/web.xml"/>
</target>
<target name="create-ejb-client" depends="build-ejb-client">
<jar destfile="${outputartifacts}/${ejbclient.name}.jar" basedir="${ejbclient.builddir.classes}" includes="**/*"/>
</target>
<target name="create-ejb" depends="build-ejb">
<jar destfile="${outputartifacts}/${ejb.name}.jar" basedir="${ejb.builddir.classes}" includes="**/*">
<manifest>
<attribute name="Class-Path" value="${ejbclient.name}.jar"/>
</manifest>
</jar>
</target>
<target name="create-ear" depends="create-ejb-client,create-web,create-ejb">
<ear destfile="${outputartifacts}/${ear.name}.ear" appxml="${ear.dir}/EarContent/META-INF/application.xml">
<fileset dir="${outputartifacts}" includes="*.jar,*.war"/>
</ear>
</target>
</project>
`
Use Maven.
Maven allow to define all dependencies in a single xml file (pom), dependencies which will be automatically downloaded from internet at compilation phase.
Maven come with a set of plugin to facilitate continuous integration like being able to start a container, run the test and close it automatically.
Maven integrate natively with jenkins.
Maven defines a complex lifecycle designed for this kind of problematic and allowing to compile, run unit test, package, run integration test and deploy with a single command triggered from jenkins;
Maven is definitively THE solution here.
You can also auto-create the build.xml in Eclipse using "Export... > General\Ant Buildfile" from the project context menu. This way the correct classpath is generated to your JAR's already available in the project.
Chances are that if there are dependencies between the projects, you only need to configure one build file to be run on Jenkins, as it will automatically call the build files from the other projects.

Folder with jars in project

When I work on small desktop projects I used to create lib folder in my project's root where I keep all project's jar dependencies. Then I use Configure Build Path -> Libraries -> Add JARs... to manually add all jars from this folder to buildpath/classpath. And because Add JARs... (unlike Add external JARs) uses relative paths, the project is portable, what is important for me.
The problem is that each time I add or remove a jar from my lib folder I need to manually add/remove this jar in project buildpath settings (and of course I often forget to do so).
Is there a way to just inform Eclipse that "This is a folder where I keep all of my jars. Please, add all the jars from there automatically to buildpath/classpath"? I tried to treat this folder as a class folder (Add class folder...) but it doesn't work that way :(.
P.S. I know about Maven and Eclipse-Maven integration but I want to keep my small project's simple (Maven integration is sometimes frustrating so I prefer to avoid it in these projects), so please don't suggest this in answer. Also as I mentioned, these are desktop projects, so there is no WEB-INF/lib folder in my project that is usually automatically handled by Java EE plugins.
you can try with a classpath container, take a look here for an example .
Take a look also at the Apache IvyDE classpath container .
However adding a new library to the classpath is simple and quick as :
Right click on it ---> Build Path ---> Add To Build Path
EDIT
This lightweight plugin should do exactly what you want !
I am not too sure, but can't you have wildcards in your classpath? That way you could just edit your .classpath file for that Eclipse project and use * within a particular folder... I have not tried, i'm in a rush but that's my idea... don't know if works
EDIT here is something that you could find useful:
How to use a wildcard in the classpath to add multiple jars?
Basically, just edit your .classpath file, which is where Eclipse stores the classpath settings for a project
I think the best is to use Gradle. This does not have the frustration of Maven with Eclipse. If you use STS it comes with Gradle pre-bundled.
See the link
So yeah I did this before:
Use Apache Ant and specify an ant configuration that suits your build path and eclipse should be able to use it with the use from existing ant build option.
Here is an example ant file you might have:
<?xml version="1.0"?>
<project name="Demo Project" basedir="." default="package">
<!-- ================================================================= -->
<!-- C O N F I G U R A T I O N -->
<!-- ================================================================= -->
<!--
Access the environment properties
-->
<property environment="env" />
<!--
TODO: Access the environment properties with a prefix of "env".
-->
<!--
Additional 3rd-party tools
-->
<property name="ant.home" value="${env.ANT_HOME}"/>
<property name="junit.home" value="${env.JUNIT_HOME}"/>
<property name="jmock.home" value="${env.JMOCK_HOME}"/>
<!--
Project folders
-->
<property name="project.home" value="${basedir}" />
<property name="bin.dir" value="${project.home}/bin" />
<property name="dist.dir" value="${project.home}/dist" />
<property name="dist.file" value="${dist.dir}/lab03.jar" />
<property name="col.file" value="${dist.dir}/lab03-col.jar" />
<property name="src.dir" value="${project.home}/src" />
<property name="lib.dir" value="${project.home}/lib" />
<!--
TODO: Define the classpath to be used during compilation. This should
consist of all of the JAR files in the ${lib.dir} folder.
-->
<path id="project.class.path">
<path location="${dist.file}" />
<path location="${bin.dir}" />
<fileset dir="${junit.home}">
<include name="junit-4.7.jar"/>
</fileset>
<fileset dir="${jmock.home}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${ant.home}/lib">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<!--
TODO: Define the classpath to be used during execution. This should
consist of all of the JAR files in the ${lib.dir} folder as well as
${dist.file}.
-->
<path id="execution.class.path">
<path location="${bin.dir}" />
<path location="${bin.dir}/MyPath1/MyPath" />
<path location="${bin.dir}/MyPath1/MyPath/impl" />
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<!-- ================================================================= -->
<!-- C L E A N -->
<!-- ================================================================= -->
<target name="clean"
description="Clean all build products">
<delete dir="${bin.dir}" />
<delete dir="${dist.dir}" />
</target>
<!-- ================================================================= -->
<!-- C O M P I L E -->
<!-- ================================================================= -->
<target name="compile"
depends="clean,init"
description="Compiles the application code">
<!--
TODO: Add the javac task. It should compile everything in ${src.dir}
and place the output in ${bin.dir}. The classpath should refer to the
"project.class.path" defined above.
-->
<javac srcdir="${src.dir}"
destdir="${bin.dir}">
<classpath refid="project.class.path" />
</javac>
</target>
<!-- ================================================================= -->
<!-- E N V -->
<!-- ================================================================= -->
<target name="env"
description="Displays information about the build">
<echo message="src.dir..........${src.dir}" />
<echo message="lib.dir..........${lib.dir}" />
<echo message="bin.dir..........${bin.dir}" />
<echo message="dist.dir.........${dist.dir}" />
<echo message="dist.file........${dist.file}" />
<echo message="col.file.........${col.file}" />
<echo message="reports.dir......${reports.dir}" />
</target>
<!-- ================================================================= -->
<!-- I N I T -->
<!-- ================================================================= -->
<target name="init"
depends="env"
description="Initializes the environment">
<mkdir dir="${bin.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<!-- ================================================================= -->
<!-- P A C K A G E -->
<!-- ================================================================= -->
<target name="package"
depends="compile"
description="Creates the application distribution file">
<!--
TODO: Create a JAR file. The target JAR should be ${dist.file} and it
should contain everything from ${bin.dir}.
-->
<jar destfile="${dist.file}"
basedir="${bin.dir}"
excludes="**/*Test*.class"
/>
</target>
<!-- ================================================================= -->
<!-- P A C K A G E - C O L -->
<!-- ================================================================= -->
<target name="package-col"
depends="compile"
description="Creates the file to be submitted to COL.">
<jar destfile="${col.file}">
<fileset dir="${project.home}"
includes="src/**/*.java" />
<fileset dir="${project.home}"
includes="lib/**/*.jar" />
<fileset dir="${project.home}"
includes="build.xml" />
</jar>
</target>
<!-- ================================================================= -->
<!-- R U N -->
<!-- ================================================================= -->
<target name="run"
depends="package"
description="Executes the test file">
<java classname="MyPath1.MyPath.FileScanner">
<classpath refid="execution.class.path" />
<arg value="file:///" />
</java>
</target>
</project>
AND Here is a link with someone with a similair problem using ant to solve his classpath problems.
Ant is portable so it can actually be set up anywhere and you can also use global variables to keep all systems consistent or just use relative paths. And there is also an eclipse ant plugin
just try including
<classpathentry kind="lib" path="lib/spring/4.2.1" including="*.jar"/>

How to conditionally include manifest options when making a JAR in ANT

I am using ANT to manage multiple projects. I have a build-common.xml script that individual projects include. Some projects are libraries, others are programs. For the programs, I would like to include
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
in the <jar> tag. For libraries, I would like to have an empty jar tag as follows.
<target name="jar" depends="compile" description="generate a jar">
<mkdir dir="${build}/jar" />
<property name="jarfile" value="${jar}/${ant.project.name}.jar" />
<jar jarfile="${jarfile}" basedir="${classes}">
</jar>
</target>
Is there a way I can include the manifest attribute Main-Class only if the property main.class is defined?
Thanks!
Use conditional targets:
<target name="jar-mkdir" depends="compile" description="generate a jar">
<mkdir dir="${build}/jar" />
<property name="jarfile" value="${jar}/${ant.project.name}.jar" />
</target>
<target name="jar-main" depends="compile" description="generate a jar" if="main.class">
<jar jarfile="${jarfile}" basedir="${classes}">
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
</target>
<target name="jar-nomain" depends="compile" description="generate a jar" unless="main.class">
<jar jarfile="${jarfile}" basedir="${classes}">
</jar>
</target>
<target name="jar" depends="compile, jar-mkdir, jar-main, jar-nomain" description="generate a jar">
</target>
This will run jar-main (and add the manifest) only when main.class is present. When it is not present jar-nomain will run.