Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

I've written articles about building web services using Maven in the past as well as various other articles to do with Maven in general. This time I want to cover how Maven's dependency mechanism relates to WAR file packaging, specifically to the WEB-INF/lib directory.

I'm going to use JUnit as the dependency since it is pretty much guaranteed to be available in any Maven repository. Hence, my dependency inside the pom.xml is defined like this (minus the scope element)...
 pom.xml
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>


There are 5 dependency scopes available (actually 6 but the import scope is not of interest here). The default scope is compile. Taking each of the scopes into account this is what will be packaged inside the WEB-INF/lib directory inside the WAR file when each of the scopes is used...

Scopes: compile, runtime:
mvndep_compile_runtime.png


For the compile and runtime scopes, the WEB-INF/lib directory will contain the JAR files of the dependencies as well as any dependencies that the project's dependencies have that use a transient scope. For example since JUnit depends on Hamcrest Core, both the junit-4.12.jar and hamcrest-core-1.3.jar files are included in the WEB-INF/lib directory.



Scopes: provided, test, system:
mvndep_provided_test_system.png


For the provided, test and system scopes the WEB-INF/lib directory will not contain JAR files of the dependencies. In this case the WEB-INF/lib directory is not created at all since there aren't any other JARs are inside it.

As a side note - NEVER use the system scope in a J2EE project unless there is a really good reason for it (usually there isn't).

-i

Please leave your comments or feedback below!
comments powered by Disqus
Other posts you may like...
Hi! You can search my blog here ⤵
Or browse the recent top tags...

Recent Blog Posts

How to stop macOS adding shadows to window screenshots

How to run Atari Lynx games on the SNES Classic Mini

Maven dependency scopes with relation to WAR file packaging and the WEB-INF/lib directory

Hacking the Sonoff B1 WiFi LED bulb to run custom firmware

What does an idle WebLogic server run on the hour to cause a CPU spike

How to open the Sonoff B1 wifi LED bulb to access its internal circuitry

Australian release SNES mini classic unboxing and a quick play through

Troubleshooting high CPU usage for JVM threads

How to fix WebLogic high CPU usage due to a corrupted file store

Mini review of the Sonoff B1 WiFi light bulb

Recent Galleries

Atari Lynx repair - Part 5 - McWill LED screen mod installation

Atari Lynx repair - Part 4 - screen cover replacement

Atari Lynx repair - Part 2 - re-capping the motherboard

Atari Lynx repair - Part 3 - broken speaker replacement

Atari Lynx repair - Part 1 - introduction and case disassembly

Building a custom Atari Lynx game box storage shelf unit in a day

Protecting old Atari Lynx game boxes with snug fit plastic sleeves

Monument Valley 2 is released and does not disappoint

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

Blogs and Friends

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity