June 2005
Beginner
224 pages
5h 40m
English
Now that you've generated the client library, use Maven to execute the mdn.weather.Weather class and obtain the
weather report for Chicago, Illinois.
Define a custom goal in maven.xml that uses Ant's java task to execute the mdn.weather.Weather class:
<goal name="weather:run" prereqs="jar">
<ant:java classname="mdn.weather.Weather" fork="true">
<ant:arg value="41.30"/>
<ant:arg value="-87.51"/>
<ant:arg value="1"/>
<ant:classpath>
<ant:pathelement
location="${maven.build.dir}/${maven.final.name}.jar"/>
<ant:pathelement
location="${pom.getDependencyPath('commons-discovery:commons-discovery')}"/>
<ant:pathelement
location="${pom.getDependencyPath('commons-logging:commons-logging')}"/>
<ant:pathelement location="${pom.getDependencyPath('axis:axis')}"/>
<ant:pathelement
location="${pom.getDependencyPath('axis:axis-jaxrpc')}"/>
<ant:pathelement location="${pom.getDependencyPath('axis:axis-saaj')}"/>
<ant:pathelement location="${pom.getDependencyPath('axis:axis-wsdl4j')}"/>
</ant:classpath>
</ant:java>
</goal>The Weather class takes three
arguments—latitude, longitude, and number of forecast days. In this
goal, we've specified the coordinates for Chicago and a single day.
When we execute the maven
weather:run goal we get the response in the form of an XML
document containing our forecast:
<?xml version='1.0' ?> <dwml version='1.0' xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> // ...
Read now
Unlock full access