gpt4 book ai didi

java - Maven:包 org.junit 不存在

转载 作者:行者123 更新时间:2023-11-30 08:16:13 25 4
gpt4 key购买 nike

我是 Maven 新手,如果这太基本了,请原谅。我搜索过这个问题,每个人似乎都解决了这个问题,从pom.xml文件中删除标签。

我那里没有那个标签:

<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>GraphApp</groupId>
<artifactId>GraphApp</artifactId>
<version>1.0.0</version>
<name>MyApp</name>
<description>MyApp</description>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

我已经用Eclipse转换了一个现有的项目,所以问题可能就出在这里。

另外,我读到 Maven 的默认模式是将代码存储在一些默认文件夹中,而我使用的是 src/com/romanrdgz/core/myapp/test/com/romanrdgz/test/core。这也可能是问题的根源。

我看到这个错误:

Maven: package org.junit does not exist

我需要改变什么?

编辑:好的,我已将 JUnit4 作为依赖项包含在内,并且还将我的文件夹更改为如下所示: enter image description here

不过,当我转到控制台并执行 mvn testmvncompile 时,我得到以下输出:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building GraphApp 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ GraphApp -
--
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\rrrp\workspace\GraphApp\src\
main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ GraphApp ---
[INFO] Nothing to compile - all classes are up to date
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.515 s
[INFO] Finished at: 2015-04-15T08:15:06+02:00
[INFO] Final Memory: 11M/309M
[INFO] ------------------------------------------------------------------------

我尝试删除 bin 和 target 文件夹,但还是一样。看起来它没有找到类或测试。

有什么帮助吗?

最佳答案

将 junit 依赖项添加到 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">

.....
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
</project>

关于java - Maven:包 org.junit 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29631380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com