September 2008
Intermediate to advanced
470 pages
14h 22m
English
Using the Exec plugin from the Codehaus Mojo project, we
can execute this program. To execute the
Main class, run the following command from the
project’s base directory:
$ mvn install
$ mvn exec:java -Dexec.mainClass=org.sonatype.mavenbook.weather.Main
...
[INFO] [exec:java]
0 INFO YahooRetriever - Retrieving Weather Data
134 INFO YahooParser - Creating XML Reader
333 INFO YahooParser - Parsing XML Response
420 INFO WeatherFormatter - Formatting Weather Data
*********************************
Current Weather Conditions for:
Evanston, IL, US
Temperature: 45
Condition: Cloudy
Humidity: 76
Wind Chill: 38
*********************************
...We didn’t supply a command-line argument to the
Main class, so we ended up with the default zip
code, 60202. To supply a zip code, we would use the
-Dexec.args argument and pass in a zip code:
$ mvn exec:java -Dexec.mainClass=org.sonatype.mavenbook.weather.Main \
-Dexec.args="70112"
...
[INFO] [exec:java]
0 INFO YahooRetriever - Retrieving Weather Data
134 INFO YahooParser - Creating XML Reader
333 INFO YahooParser - Parsing XML Response
420 INFO WeatherFormatter - Formatting Weather Data
*********************************
Current Weather Conditions for:
New Orleans, LA, US
Temperature: 82
Condition: Fair
Humidity: 71
Wind Chill: 82
*********************************
[INFO] Finished at: Sun Aug 31 09:33:34 CDT 2008
...As you can see, we’ve successfully executed the simple weather command-line tool, retrieved some ...