3
votes

I created a project in Eclipse (Oxygen) using maven with no archetype. My question is ... to use the Servlet API, if I use "Project Properties> Project Faces" and add "Dynamic Web Module", is it the same as adding the dependency in pom.xml of the Servlet API (javax. servlet-api)?

I mean...

Project Properties > Project Facets > Dynamic Web Module 4.0 (Checked)

Is the same as...?

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>4.0</version>
  <scope>provided</scope>
</dependency>

Project Facets

Maven Dependency

2
Did you try anything? What did you find when you added the facet?Jim Garrison
I guess it doesn't do same thing, as I tried creating a project as you mentioned, and selected project facets, updated maven project but it hasn't added any servlet dependency to the pom. I think project facets are for runtime configuration.Adya

2 Answers

1
votes

Project facets allows IDE to understand your project better so that it can perform some special operations for you. For example, applying Dynamic Web Module would make eclipse know that your Project would be running on Web Server, hence you would need that facet to add your project to a Web Server. As you apply Dynamic Web Module to your project, eclipse also assumes that you would be provided with web server dependencies in the run time. Facets stays at IDE level.

While maven dependency provides you with the libraries required in your project to perform your task. They stay with your project package when it is deployed.

0
votes

instead of

 <dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0</version>
<scope>provided</scope>

Go to Project properties > Project facets > click on runtimes which is in right side of Project Facets > checked that server >Apply and close

enter image description here