maven - "java: package org.junit does not exist"即使它在 Maven pom 中

标签 maven junit configuration dependencies

我在我的项目中收到“java:package org.junit 不存在”,这让我发疯。我将 JUnit 作为外部库,但它仍然无法识别这一点。我正在尝试在 IntelliJ Idea 中设置一个简单的“Hello World”应用程序。

这是我的 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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.springapp</groupId>
    <artifactId>untitled</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>untitled</name>

    <properties>
        <spring.version>4.1.1.RELEASE</spring.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>untitled</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <includes>
                        <include>**/*Tests.java</include>
                    </includes>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

更新:我能够在另一台计算机上运行完全相同的项目。这很奇怪。

最佳答案

你可以试试这个:

mvn idea:idea

它将生成您的 IntelliJ IDEA 项目所需的文件。

关于maven - "java: package org.junit does not exist"即使它在 Maven pom 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32792053/

相关文章:

java - 尝试使用 maven 安装项目时出现 NoClassDefFoundError

java - JAX-RS 服务的集成测试

java - JUnit 和通过公共(public) api 导出非公共(public)类型的警告

tomcat - jenkins在哪里存储作业和节点配置

c++ - Linux 配置文件库

java - 黑名单 Maven 依赖项

java - 父 pom 和微服务

java - 构建 war 文件时出现编译错误

java - 如何使使用 maven-assembly-plugin 生成的 WAR 存档可用于其​​他项目的单元测试?

java - 获取 Spring 应用程序上下文