【发布时间】:2015-09-25 23:34:09
【问题描述】:
我在我的项目中得到“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>
更新:我能够在我的另一台计算机上运行相同的项目。这很奇怪。
【问题讨论】:
-
删除你的 m2 repo,并发布
mvn -U clean install的结果。 -
@Tunaki 我正在使用 intellij idea 的内置 maven。这样做适用于我的另一台 Mac。
-
我建议您删除本地 m2 存储库,因为它可能已损坏。这意味着删除目录 ~/.m2/repository (这是默认的)
标签: maven junit configuration dependencies