mkayman
mkayman

Reputation: 110

Why Maven compiles successfully without Servlet dependency?

I am writing a spring-mvc app (and learning spring-mvc). I didn't add servlet dependency to pom.xml. When I run mvn compile or mvn package, it finishes succesfully. Isn't it suppose to throw exception like 'can not find javax.servlet.http.HttpServlet'? How does it compile?

mvn dependency:list:

The following files have been resolved: [INFO]
aopalliance:aopalliance:jar:1.0:compile [INFO]
commons-dbcp:commons-dbcp:jar:1.4:compile [INFO]
commons-pool:commons-pool:jar:1.5.4:compile [INFO]
log4j:log4j:jar:1.2.17:compile [INFO]
org.codehaus.jackson:jackson-core-asl:jar:1.9.12:compile [INFO]
org.codehaus.jackson:jackson-mapper-asl:jar:1.9.12:compile [INFO]
org.slf4j:jcl-over-slf4j:jar:1.7.2:compile [INFO]
org.slf4j:slf4j-api:jar:1.7.2:compile [INFO]
org.slf4j:slf4j-log4j12:jar:1.7.2:compile [INFO]
org.springframework:spring-aop:jar:3.2.1.RELEASE:compile [INFO]
org.springframework:spring-beans:jar:3.2.1.RELEASE:compile [INFO]
org.springframework:spring-context:jar:3.2.1.RELEASE:compile [INFO]
org.springframework:spring-core:jar:3.2.1.RELEASE:compile [INFO]
org.springframework:spring-expression:jar:3.2.1.RELEASE:compile [INFO] org.springframework:spring-jdbc:jar:3.2.1.RELEASE:compile [INFO]
org.springframework:spring-tx:jar:3.2.1.RELEASE:compile [INFO]
org.springframework:spring-web:jar:3.2.1.RELEASE:compile [INFO]
org.springframework:spring-webmvc:jar:3.2.1.RELEASE:compile [INFO]
postgresql:postgresql:jar:9.2-1002.jdbc4:compile

Upvotes: 0

Views: 264

Answers (3)

apurvc
apurvc

Reputation: 750

Not totally realated: Still as you are learning spring-mvc I suggest keeping only the required dependency in pom which will tell you which jar has which set of classes.

Also configure logging and put debug for spring specific package which greatly supports understanding the flow or what may be wrong. It helped me a lot when I started with spring. Happy learning :)

Upvotes: 0

Sudhakar
Sudhakar

Reputation: 4873

Its because , the Servlet Api is a transitive dependency of spring-webmvc. By default Maven includes all transitive dependencies.

Use the below command to list dependencies & its transitive dependencies

mvn dependency:tree

Upvotes: 1

JB Nizet
JB Nizet

Reputation: 692281

Because the servlet API is a dependency of org.springframework:spring-webmvc, and thus a transitive dependency of your project.

Upvotes: 0

Related Questions