"Maven项目无法识别某些构件"

4
我是新手,刚开始使用Maven,这可能是个愚蠢的问题。我的问题是我在Eclipse Luna版本中创建了一个动态Web项目。我已经在pom文件中添加了一些构件,JAXRS和DOM4J。它下载了所有的jar包。
我能够在代码中导入JAXRS类而不需要在lib文件中添加jaxrs。 但是我无法访问DOM4J类。我正在使用web-sphere作为我的服务器。
请帮我解决dom4j的问题。提前感谢您的帮助。
POM文件.. 我已经在本文中删除了一些条目。
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.mycompany.app</groupId>
      <artifactId>.......</artifactId>
      <version>1</version>

      <build>
        <defaultGoal>install</defaultGoal>
      </build>
      <dependencies>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.0</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
.....
.....
        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.5</version>
        </dependency>

      </dependencies>
    </project>

我的类路径

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/WebSphere Application Server v8.0 JRE">
        <attributes>
            <attribute name="owner.project.facets" value="java"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" path=".apt_generated">
        <attributes>
            <attribute name="optional" value="true"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="src" path="src/main/java"/>
    <classpathentry kind="src" path="src/main/resources"/>
    <classpathentry kind="con" path="org.eclipse.jst.server.core.container/com.ibm.ws.ast.st.runtime.runtimeTarget.v80/WebSphere Application Server v8.0">
        <attributes>
            <attribute name="owner.project.facets" value="jst.web"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
    <classpathentry kind="output" path="WebContent/WEB-INF/classes"/>
</classpath>

我正在使用Websphere 8作为我的服务器。

1个回答

3
如果您像您所提到的那样下载了Jar文件,那么只需要按照以下步骤进行操作即可。如果您已经在Eclipse中添加了Marketplace中的Maven,则很好,如果没有,请先添加Maven。
Right click on your Project->Maven->Update the Project

它将解决与依赖性相关的问题。

或者

尝试这个命令

mvn clean -U

mvn clean install -U

mvn eclipse:eclipse -U

请参阅Maven:完全参考,6.1.11。下载和验证依赖项mvn --help

-U,--update-snapshots    Forces a check for missing
                         releases and updated snapshots on
                         remote repositories

它起作用了。我已经使用了命令。你能告诉我问题在哪里吗?非常感谢。 - user4485029
“-U” 用于强制更新,将会给你更多的细节。 - Subodh Joshi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接