Tag Archives: ant

Adding manifest attributes to existing JAR file

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

<build>
    <plugins>
    ...
    
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.6</version>
            <executions>
                <execution>
                    <id>repack</id>
                    <phase>package</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <target>
                            <jar update="true" 
                                 file="${project.basedir}/some.jar">
                                <manifest>
                                    <attribute name="Class-Path" 
                                               value="jackson.jar"/>
                                </manifest>
                            </jar>
                        </target>
                    </configuration>
                </execution>
            </executions>
        </plugin>    
    
    </plugins>
</build>

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

Docs:
https://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html
http://www.softlab.ntua.gr/facilities/documentation/unix/java/tutorial/jar/basics/mod.html
http://introcs.cs.princeton.edu/java/85application/jar/jar.html

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

Passing command line arguments to ant script file

ant-promt
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}" />
    </target>
</project>

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

hor
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}"/>
 	</exec>
</target>

</project>

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

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

Where src/resources/auth is like:


http://userName:userPass@key-provider.com/keyws?wsdl

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/