Hi,

Jay SenSharma

Jay SenSharma

Many times we want to add all the Jars available in a perticular directory in out ANT tasks or for that ant target…rather than adding all the jar filenames separately …it can be achieved by doing the following …

<path id=”project.classpath”>
<pathelement path=”${java.class.path}”/>
<fileset dir=”${basedir}/myJarsDirectory”>
<include name=”*.jar” />
</fileset>
</path>

Now refer to the above classpath reference in your ANT-TASK like:

Option-1). With Container Specific tasks
<jwsc srcdir=”src” destdir=”${ear-dir}” keepGenerated=”true” classpathref=”project.classpath” >

Option-2). With Container Specific tasks
<jwsc srcdir=”src” destdir=”${ear-dir}” keepGenerated=”true” >
<jws file=”examples/MyHelloService.java”/>
<classpath>
<fileset dir=”${basedir}/myJarsDirectory”>
<include name=”*.jar” />
</fileset>
</classpath>
</jwsc>

Option-3). with Java Compiler
Same thing we can do while compiling our classes using ANT task:

<javac classpath =”compile.classpath” srcdir=”${clientclass-dir}” destdir=”${clientclass-dir}” debug=”on” deprecation=”on” includes=”**/*.java” >
<classpath>
<fileset dir=”${basedir}/myJarsDirectory”>
<include name=”*.jar” />
</fileset>
</classpath>
</javac>

Or

<javac classpath =”compile.classpath” srcdir=”${clientclass-dir}” destdir=”${clientclass-dir}” debug=”on” deprecation=”on” includes=”**/*.java” >
<classpath refid=”project.classpath”/>
</javac>

Option-4). With Java.exe
<target name=”run”>
<java fork=”true” classname=”examples.client.Main” failonerror=”true” >
<classpath refid=”client.class.path”/>
<classpath>
<fileset dir=”${basedir}/myJarsDirectory”>
<include name=”*.jar” />
</fileset>
</classpath>
<arg line=”http://${wls.hostname}:${wls.port}/myHelloServiceRoot/ServiceUri?WSDL” />
</java>
</target>

.
.
.
Thanks
Jay SenSharma

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.