servlet packages not importing after converting project to maven project in eclipse

别来无恙 提交于 2019-12-11 08:26:30

问题


I have a dynamic web application that I've converted to a maven project in Spring Toolsuite (Eclipse, basically.) The project now has a pom.xml file, but the Java Build Path no longer has the jars I used to use because maven is supposed to handle the dependencies. I put the dependencies in the pom like this:

<dependencies>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>(,1.0]</version>
    </dependency>
  </dependencies>

and I included a repository like so:

<repositories>
        <repository>
          <id>maven2-repository.dev.java.net</id>
          <name>Java.net Repository for Maven</name>
          <url>http://download.java.net/maven/2/</url>
          <layout>default</layout>
        </repository>
  </repositories>

Still, the dependency isn't resolved and my servlets aren't working. Why isn't my converted Maven project making dependency management any easier? Why aren't the servlet imports working, more specifically?


回答1:


You can add the dependencies to the deployment by:

  1. Right click the project > Project Properties
  2. Click Deployment Assembly
  3. Click Add
  4. Click Java Build Path Entries
  5. Click Maven Dependencies

You can add the dependencies to the build path by:

  1. Right click the project > Project Properties
  2. Click Java Build Path
  3. Click Libraries
  4. Click Add Libraries
  5. Select Maven Managed Dependencies

You shouldn't be importing the servlet dependencies via Maven though, you should be pointing at your servers runtime. You can configure this by:

  1. Right click the project > Project Properties
  2. Click Java Build Path
  3. Click Libraries
  4. Click Add Libraries
  5. Select Server Runtime
  6. Select your server.



来源:https://stackoverflow.com/questions/16409149/servlet-packages-not-importing-after-converting-project-to-maven-project-in-ecli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!