Our project is a simple web application, and to begin, it will need JUnit as a dependency for testing and log4j
for logging purposes. As we progress further, we will add more dependencies progressively; the idea of this section is to show how to add dependencies in the pom
file. If we see our pom
file, we can see that JUnit is already present as a dependency; so, let's add log4j
as a dependency by adding the following code snippet:
<project> ….... <dependencies> … <!-- For logging purpose --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> </dependencies> ….... </project>
The complete resultant pom
file would look like the following:
<project xmlns="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"> <modelVersion>4.0.0</modelVersion> <groupId>com.packt.mvneclipse</groupId> <artifactId>MyDistance</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>MyDistance Maven Webapp</name> <url>http://maven.apache.org</url> <!-- Organization information --> <organization> <name>Packt Publishing</name> <url>www.packtpub.com</url> </organization> <!-- License information --> <licenses> <license> <name>Apache 2</name> <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> <distribution>manual</distribution> <comments>A Friendly license</comments> </license> </licenses> <!-- Developers Information --> <developers> <developer> <id>foo</id> <name>Foo foo</name> <email>[email protected]</email> <url>http://www.foofoo.net</url> <organization>Packt</organization> <organizationUrl>http://packtpub.com</organizationUrl> <roles> <role>developer</role> </roles> <timezone>-8</timezone> </developer> </developers> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <!-- For logging purpose --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> </dependencies> <build> <finalName>MyDistance</finalName> </build> </project>
3.15.12.34