Tag Archives: ant

Adding manifest attributes to existing JAR file

To modify manifest in external existing JAR file in JAVA do:

                            <jar update="true" 
                                    <attribute name="Class-Path" 

Thanx to http://stackoverflow.com/a/20634999


The bad idea is to compress JAR file with ZIP: http://stackoverflow.com/a/7085511

Passing command line arguments to ant script file

You may know such ant task as Input – http://ant.apache.org/manual/Tasks/input.html.
It promts user to enter some stuff. But what if you want to run script without promt but using command line arguments only?
Ant presents the awesome solution: just use -D option!
See more at http://ant.apache.org/manual/running.html

Consider we have ant script run.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>

<project name="someProject" default="someTask" basedir=".">
    <taskdef resource="net/sf/antcontrib/antlib.xml" />

    <target name="someTask">
        <input message="Enter first argument" addproperty="arg.first" />
        <input message="Enter second argument" addproperty="arg.second" />
        <!-- your code here... -->
        <copy file="arg.first" tofile="${arg.second}" />

To run it in batch mode use:

  ant -buildfile run.xml someTask -Darg.first=111.txt -Darg.second=111_copy.txt

Thanx to http://stackoverflow.com/a/14309773

Print Path object in Ant

To echo the path object use next:

<ivy:cachepath pathid="war.lib.id" conf="war" type="war" transitive="false" />

<pathconvert pathsep="${line.separator}" property="echo.classpath" 
  refid="war.lib.id" />
<echo message="The following classpath is associated with war.lib.id" />
<echo message="${echo.classpath}" />

Thanx to http://www.vogella.com/articles/ApacheAnt/article.html#classpath_print

WebService build by WSDL with Ant and wsimport

Just create a progect and ant build file with:

<?xml version="1.0" encoding="utf-8" ?>
<project name="wsNameClent" basedir=".">

<property name="wsdl" value="http://localhost:8080/wsSome?wsdl"/>
<target name="wsimport">
 	<exec executable="wsimport" >
 		<arg value="-verbose"/>
 		<arg value="-keep"/>
 		<arg value="-d"/>
 		<arg value="bin"/>
 		<arg value="-s"/> 
 		<arg value="src"/>
 		<arg value="${wsdl}"/>


If you’ve to provide authorized access add to args:

	<arg value="-Xauthfile"/>
	<arg value="src/resources/auth"/>

Where src/resources/auth is like:


No one code typing!

To test your svc use like this:

TwitService svc = new TwitService();
GetAllTwitsResponse resp = svc.getTwitSoap11().getAllTwits(new GetAllTwitsRequest());
for (Twit_Type tw : resp.getTwit())
	System.out.println(tw.getNick() + " - " + tw.getMessage());

Also, good java webservices tutorial http://www.mkyong.com/tutorials/jax-ws-tutorials/