【问题标题】:java ee api is missing in project classpath test项目类路径测试中缺少 java ee api
【发布时间】:2016-10-25 14:37:07
【问题描述】:

我正在尝试为 servlet 创建一个简单的 UnitTest。显然,maven 存在一些问题(我认为)会影响构建过程。

我做了一些研究,显然这是一个已知问题。根据我的不足,需要做的是更改 pom.xml 中 javaee-web-api 依赖项的位置

不幸的是,这个解决方案对我不起作用。这非常令人沮丧,因为我花了很多时间在配置而不是编码上。

知道如何解决这个问题或其他一些测试解决方案吗?

我正在使用 Maven 和 NetBeans。

谢谢

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-core</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
    </plugins>
</build>

【问题讨论】:

  • provided 的意思是“已经在类路径上”,也许你想用 test 代替?
  • 你能发布错误吗?您的项目 Dynamic Web Module 版本是多少?
  • 6.0 javax/javaee-* 人工制品因这个问题而臭名昭著。它们可以编译,但它们已被剥夺了允许它们在运行时使用所需的内容。

标签: java maven unit-testing netbeans-8


【解决方案1】:

添加 org.glassfish.extras 依赖解决。

看到这个问题:Testing against Java EE 6 API

<modelVersion>4.0.0</modelVersion>

<groupId>com.mycompany</groupId>
<artifactId>mavenproject1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<name>mavenproject1</name>

<dependencies>
    <dependency>
        <groupId>org.glassfish.extras</groupId>
        <artifactId>glassfish-embedded-all</artifactId>
        <version>3.0.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-core</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>6.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
    </plugins>
</build>
<repositories>
    <repository>
        <id>glassfish-extras-repository</id>
        <url>http://download.java.net/maven/glassfish/org/glassfish/extras</url>
    </repository>
</repositories>

【讨论】:

    猜你喜欢
    • 2011-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-17
    • 1970-01-01
    • 1970-01-01
    • 2017-06-19
    • 2011-04-07
    相关资源
    最近更新 更多