Writing a Custom Goal
To generate a client library for a SOAP service, you need to download the WSDL you are
going to pass to wsdl2java
. Define a
custom goalâweather:get-wsdl
âto
download the service description from NOAA.
How do I do that?
To write your own goal, add some Jelly script to the weather/maven.xml file. Here's a simple
custom goal that retrieves a WSDL document with Ant's get
task. The custom goal is defined as
follows:
<?xml version="1.0" encoding="UTF-8"?> <project xmlns:j="jelly:core" xmlns:ant="jelly:ant" xmlns:maven="jelly:maven" default="jar"> <goal name="weather:get-wsdl" description="Retrieves WSDL document"> <j:set var="wsdl" value="http://weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl"/> <ant:echo>Retrieving WSDL from ${wsdl}</ant:echo> <ant:get src="${wsdl}" dest="${basedir}/src/wsdl/weather.wsdl"/> </goal> </project>
The value of the ${wsdl}
property is set with j:set
, a
message is printed to the console, and the document is retrieved and
saved to weather/src/wsdl. This
script uses the echo
task from
Apache Ant to print out a message, and you can run it from the command
line with maven
weather:get-wsdl
, which produces the
following output:
Note
In your project, the URL of the WSDL document should be defined in project.properties. This will make configuration much easier.
C:\dev\mavenbook\code\weather>maven weather:get-wsdl
_ _ _ _ | \/ |_ _ _Apache_ _ _ _ _ | |\/| / _` \ V / -_) ' \ ~ intelligent projects ~ |_| |_\_ _,_|\_/\_ _ _|_||_| v. 1.0.2 build:start: ...
Get Maven: A Developer's Notebook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.