1

我已经阅读了看起来相似的帖子,但我还没有找到任何导致解决方案的帖子。

我正在 Windows 7 上的 Eclipse Juno 中进行编辑。

maven clean install war:inplace从包含两个构建错误的项目目录中的命令行运行。 注意:Maven 构建ProjectB成功。

我很确定这两个错误消息都是直接相关的。

错误

  1. The hierarchy of the type SomeClassB is inconsistent错误SomeClassB
  2. The type javax.servlet.Servlet cannot be resolved. It is indirectly referenced from required .class filesSomeClassC

导入后的类声明行中的以下代码中出现了两个错误:

import foo.bar.one.a.base.SomeClassA;
import foo.bar.two.b.property.PropertyX;

public abstract class SomeClassB extends SomeClassC{

    public SomeClassB() {
        super();
    }

    @Override
    protected PropertyX getPropertyX() {
        return SomeClassA.getPropertyX(this.getPropName());
    }

    @Override
    protected String getPropName() {
        return SomeClassA.PROPERTY_NAME;
    }

}

需要注意的一些事项:

  1. SomeClassC 在另一个项目中定义。我会叫它ProjectC
  2. 上面的代码来自ProjectB. pom.xml 文件ProjectB 确实包含对ProjectC. 见下面的代码:

pom.xml

编辑:添加了所有依赖项

<dependencies>
    <dependency>
        <groupId>com.ibm.ws</groupId>
        <artifactId>j2ee</artifactId>
        <version>7.0.0.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.ibm.wps</groupId>
        <artifactId>com.ibm.ws.portletcontainer</artifactId>
        <version>6.1.0.2</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.ibm.icu</groupId>
        <artifactId>icu4j</artifactId>
        <version>3.4.1</version>
    </dependency>
    <dependency>
        <groupId>com.ibm.jsf</groupId>
        <artifactId>jsf</artifactId>
        <version>3.0.7</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.ibm.jsf</groupId>
        <artifactId>jsf-impl-messages</artifactId>
        <version>7.0.0.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.ibm.jsf</groupId>
        <artifactId>jsf-portletbridge</artifactId>
        <version>3.1.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.ibm.jsf</groupId>
        <artifactId>jsf-ibm</artifactId>
        <version>3.0.11</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
    </dependency>
    <dependency>
        <groupId>foo.bar.one.c</groupId>
        <artifactId>foo1</artifactId>
        <version>1.2.3</version>
        <scope>provided</scope>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>foo.bar.one.c</groupId>
        <artifactId>foo2</artifactId>
        <version>${foovar2.version}</version>
    </dependency>
    <dependency>
        <groupId>foo.bar.one.c</groupId>
        <artifactId>PropertyX</artifactId>
        <version>${property.version}</version>
    </dependency>
    <dependency>
        <groupId>foo.bar.one.c</groupId>
        <artifactId>ProjectC</artifactId>
        <version>${varname.version}</version>
    </dependency>
    <dependency>
        <groupId>foo.bar.one.c</groupId>
        <artifactId>foo3</artifactId>
        <version>${foovar3.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>foo.bar.one.c</groupId>
        <artifactId>foo4</artifactId>
        <version>${foovar4.version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
</dependencies>
    <properties>
        ...
        <varname.version>5.2.85373</varname.version>
        ...
    </properties>

我已确保ProjectC该类确实存在于我的文件系统中,并且该类的路径是 .classpath 文件中的一个条目ProjectB

我尝试过的一种解决方法是导入ProjectCeclipse 并将其添加到ProjectBJava Build Path 中。我不想这样做,因为这对我的团队来说是一种不鼓励的做法。

我该如何解决这个问题?

4

2 回答 2

0

当您从命令行运行 Maven 时会发生这种情况。

简而言之,Eclipse 认为只有它自己会更改target/classes/. 如果从命令行运行 Maven,它会更改相同的文件,Eclipse 会很困惑。

你有两个选择:

  1. 使用 Project -> Clean 再次构建所有内容。

  2. 从命令行配置 Eclipse 以使用与 Maven 不同的输出文件夹进行构建。

于 2013-10-31T16:48:41.653 回答
-1

提供此依赖项

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
</dependency>
于 2013-10-31T15:00:21.700 回答