Becausesecurityvulnerabilitiesinthird-partysoftwarearesocommon, it is important to manage the versions of your dependencies and to be prepared to upgrade them quickly. For Maven projects, I recommend putting the versions of all your dependencies in the properties section of your pom.xml. Furthermore, for libraries which require multiple dependency entries in pom.xml, this allows you to ensure you use the same version for all of those dependencies.
<projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><properties><spring.version>3.2.6.RELEASE</spring.version><jackson.version>2.2.3</jackson.version></properties><dependencies><!-- spring --><dependency><groupId>org.springframework</groupId><artifactId>spring-core</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-beans</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>${spring.version}</version></dependency><!-- Jackson --><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-core</artifactId><version>${jackson.version}</version></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-annotations</artifactId><version>${jackson.version}</version></dependency><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-databind</artifactId><version>${jackson.version}</version></dependency></dependencies></project>
This creates a simple, Hello World application in the hello-world directory. We can verify it works by running it in a local servlet container using the instructions found in Supporting mvn jetty:run in Maven applications. Add the Jetty maven plugin to pom.xml under the build section:
When I’m writing a Java servlet using Maven, I find it convenient to be able to run the Java servlet in a local servlet container for testing purposes. This is very easy to do using the Jetty Maven plugin.
To add the Jetty Maven plugin to your project, modify pom.xml as follows: