A case in point

Take the Example of a Servlet’s Maven dependency

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>4.0.1</version>
    <scope>provided</scope>
</dependency>
Copy the code

The scope here is the dependency scope, and Maven will automatically determine whether to import the JAR package based on the timing

The scope parameter

Depend on the range Compile the effective The test effectively Run effectively example
compile Y Y Y spring-core
test Y Junit
provided Y Y servlet-api
runtime Y Y JDBC driver
system Y Y A local class library outside the Maven repository
  • For example, strus-core and Spring-beans are used to compile, test, and run. Enter the WAR or JAR package
  • For example, servlet-API is useful for compilation and testing, but is not used at runtime (tomcat container is provided) and does not hit WAR
  • Runtime: Test and run valid example: JDBC driver package, in the development code for Java JDBC interface development, compilation does not need to run and test through the JDBC driver package (mysQ driver) to connect to the database, if needed, will hit war
  • For example: junit does not hit WAR

Order by strength of dependence, from strongest to weakest :(understanding)

compile>provided> runtime> test