Pages

Sunday, 10 August 2014

Running without using jars in the classpath


The Exec plugin makes it possible for us to run the simplest weather program without having to load the appropriate dependencies into the classpath. In any other build system, we would have to copy all of the program dependencies into some sort of lib/ directory containing a collection of JAR files. Then, we would have to write a simple script that includes our program’s bytecode and all of our dependencies in a classpath. Only then could we run java org.sonatype.mavenbook.weather.Main. The Exec plugin leverages the fact that Maven already knows how to create and manage your classpath and dependencies.


mvn exec:java -Dexec.mainClass=org.sonatype.mavenbook.weather.Main \
      -Dexec.args="70112"


This is convenient, but it’s also nice to know exactly what is being included in your project’s classpath. Although the project depends on a few libraries such as Dom4J, Log4J, Jaxen, and Velocity, it also relies on a few transitive dependencies. If you need to find out what is on the classpath, you can use the Maven Dependency plugin to print out a

mvn dependency:resolve
  

mvn dependency:tree

Sunday, 3 August 2014

Consuming REST Services using Spring


  1.  RestTemplatemakes interacting with most RESTful services a one-line incantation. And it can even bind that data to custom domain types.
  2. As you can see, this is a simple Java class with a handful of properties and matching getter methods. It’s annotated with @JsonIgnoreProperties from the Jackson JSON processing library to indicate that any properties not bound in this type should be ignored.
  3. Because the Jackson JSON processing library is in the classpath, RestTemplate will use it (via a message converter) to convert the incoming JSON data into a Page object. From there, the contents of the Page object will be printed to the console.
    Here you’ve only used RestTemplate to make an HTTP GET request. But RestTemplatealso supports other HTTP verbs such as POSTPUT, and DELETE.
  4. http://spring.io/guides/gs/consuming-rest/

What does the spring framework do ?


  1. Dependency Injection
  2. AOP (Aspect oriented programming)
  3. Boiler plate coding removal