2015-04-14 42 views
1

我是Maven的新手,所以如果这太基本了,请原谅我。我已经搜索了这个问题,每个人似乎都解决了从pom.xml文件中移除标签的问题。Maven:包org.junit不存在

我没有这个标签有:

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

任何帮助?

+0

请张贴实际的堆栈跟踪。 – beerbajay

+0

将junit依赖关系添加到pom – Reimeus

+0

@Reimeus尝试过,但eclipse将其显示为错误。我应该在哪里添加它? –

回答

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> 
+0

好的,这完全有效。我错了。快速提问:如果我使用“mvn test”从控制台启动所有测试,我会收到警告“使用platgorm编码(实际上是Cp1252)来复制已过滤的资源”和信息“跳过不存在的资源目录C:\ Users \ myuser \ workspace \ MyApp \ SRC \测试\资源”。我的测试不在那里,但在\ MyApp \ test中。如何改变POM? –

+0

但是,我必须坚持默认的Maven文件夹结构吗?那是哪一个?或者我只需要创建一个空的test \ resources文件夹? –

+1

你不必但我会 - 更容易 – Reimeus