Maven:包org.junit不存在

时间:2015-04-14 15:27:33

标签: java eclipse maven

我是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 testmvn compile时,我得到以下输出:

[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和目标文件夹,但仍然相同。看起来它没有找到类和测试。

任何帮助?

1 个答案:

答案 0 :(得分:1)

将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>