在eclipse中将项目转换为maven项目后,不会导入servlet包 [英] servlet packages not importing after converting project to maven project in eclipse

查看:1307
本文介绍了在eclipse中将项目转换为maven项目后,不会导入servlet包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个动态Web应用程序,我已经在Spring Toolsuite(Eclipse,基本上)转换为一个maven项目。该项目现在有一个pom.xml文件,但是Java Build Path不再具有我曾经使用的jar使用,因为maven应该处理依赖。我把这样的依赖关系放在pom中:

 <依赖关系> 
<依赖关系>
< groupId> javax.servlet< / groupId>
< artifactId> servlet-api< / artifactId>
< version>(,1.0)< / version>
< / dependency>
< / dependencies>

,我包含一个这样的存储库:

 < repositories> 
< repository>
< id> maven2-repository.dev.java.net< / id>
< name>用于Maven的Java.net存储库< / name>
< url> http://download.java.net/maven/2/< / url>
< layout>默认< / layout>
< / repository>
< / repositories>

仍然依赖关系尚未解决,我的servlet不工作。为什么我的转换的Maven项目使依赖关系管理更容易?为什么servlet导入工作不是更有效?

解决方案

您可以通过以下方式将依赖项添加到部署中:


  1. 右键单击项目> Project Pro
  2. 单击部署程序集

  3. 单击添加

  4. 单击Java构建路径条目

  5. 单击Maven依赖关系



您可以通过以下方式将依赖项添加到构建路径:


  1. 右键单击项目>项目属性

  2. 单击Java构建路径

  3. 单击库

  4. 单击添加库

  5. 选择Maven管理依赖关系



您不应该导入servlet依赖项通过Maven,你应该指向你的服务器运行时。您可以通过以下方式进行配置:


  1. 右键单击项目>项目属性

  2. 单击Java构建路径

  3. 单击库

  4. 单击添加库

  5. 选择服务器运行时

  6. 选择您的服务器。


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?

解决方案

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.

这篇关于在eclipse中将项目转换为maven项目后,不会导入servlet包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆