Java Maven:包org.junit不存在

Java Maven:包org.junit不存在,java,eclipse,maven,Java,Eclipse,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.

我是马文的新手,所以请原谅,这是很基本的。我已经搜索过这个问题,每个人似乎都在从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>
我需要改变什么

编辑:好的,我已经包含JUnit4作为依赖项,并且我还将我的文件夹更改为如下:

不过,当我转到控制台并执行
mvn test
mvn 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和目标文件夹,但仍然是一样的。看起来它找不到类或测试


有什么帮助吗?

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

.....
朱尼特
朱尼特
4.11

请发布实际的堆栈跟踪。将junit依赖项添加到pom@Reimeus已尝试,但eclipse将其显示为错误。我应该将其添加到pom的哪个位置?好的,我已经发布了答案为什么要更改默认位置
src/main/java
src/test/java
?有充分的理由吗?我对此表示怀疑。好吧,这完全有效。我把它放错地方了。快速问题:如果我使用“mvn测试”从控制台启动所有测试,我会收到警告“使用platgorm编码(实际上是Cp1252)复制筛选的资源”和信息“跳过不存在的资源目录C:\Users\myuser\workspace\MyApp\src\test\resources”。我的测试不在那里,但在\MyApp\test中。如何更改pom?但是,我必须坚持默认的Maven文件夹结构吗?那是哪一个?或者我只需要创建一个空的test\resources文件夹吗?你不必,但我会-很简单,它应该有
test
标记,以避免将测试构建到最终的产品构建中。
<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>