Hi:
您好,我在学习你的mawen(二)时,输入mvn test报以下错误。麻烦帮忙指导一下?谢谢了!如下:
F:\WorkAndStudy\selfstudy\MavenProject\hello>mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Hello 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Hello ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ Hello ---
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 1 source file to F:\WorkAndStudy\selfstudy\MavenProject\hello\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Hello ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ Hello ---
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 1 source file to F:\WorkAndStudy\selfstudy\MavenProject\hello\target\test-classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] F:\WorkAndStudy\selfstudy\MavenProject\hello\src\test\java\me\gacl\maven\HelloTest.java:[6,0] 需要为 class、interface 或 enum
[ERROR] F:\WorkAndStudy\selfstudy\MavenProject\hello\src\test\java\me\gacl\maven\HelloTest.java:[8,8] 需要为 class、interface 或 enum
[ERROR] F:\WorkAndStudy\selfstudy\MavenProject\hello\src\test\java\me\gacl\maven\HelloTest.java:[10,7] 需要为 class、interface 或 enum
[ERROR] F:\WorkAndStudy\selfstudy\MavenProject\hello\src\test\java\me\gacl\maven\HelloTest.java:[11,7] 需要为 class、interface 或 enum
[ERROR] F:\WorkAndStudy\selfstudy\MavenProject\hello\src\test\java\me\gacl\maven\HelloTest.java:[12,4] 需要为 class、interface 或 enum
[INFO] 5 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.575 s
[INFO] Finished at: 2016-04-25T10:52:27+08:00
[INFO] Final Memory: 7M/122M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:testCompile (default-testCompile) on project Hello: Compilation failure: Compilation failure:
[ERROR] F:\WorkAndStudy\selfstudy\MavenProject\hello\src\test\java\me\gacl\maven\HelloTest.java:[6,0] 需要为 class、interface 或 enum
[ERROR] F:\WorkAndStudy\selfstudy\MavenProject\hello\src\test\java\me\gacl\maven\HelloTest.java:[8,8] 需要为 class、interface 或 enum
[ERROR] F:\WorkAndStudy\selfstudy\MavenProject\hello\src\test\java\me\gacl\maven\HelloTest.java:[10,7] 需要为 class、interface 或 enum
[ERROR] F:\WorkAndStudy\selfstudy\MavenProject\hello\src\test\java\me\gacl\maven\HelloTest.java:[11,7] 需要为 class、interface 或 enum
[ERROR] F:\WorkAndStudy\selfstudy\MavenProject\hello\src\test\java\me\gacl\maven\HelloTest.java:[12,4] 需要为 class、interface 或 enum
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
我怀疑是test下面的HelloTest.Java编写有问题。我的这个类是这么写的(照着你的文章写出来的)。请过目。
package me.gacl.maven;
//导入junit的包
import org.junit.Test;
import static junit.framework.Assert.*;
publicclass HelloTest {
@Test
public void testHello(){
Hello hello = new Hello();
String results = hello.sayHello("gacl");
assertEquals("Hello gacl!",results);
}
}
有qq吗?可以加一下吗?
个人认为
第一点: public class 刚才连着了,这可能是你写错了。
第二点:assertEquals("Hello gacl!",results); 很有可能抛出了异常,你看看Hello类里面是否实现equals方法,如果没实现,生成一个equals方法。
我是根据这个文章编写的。请过目!
一、创建Maven项目
1.1、建立Hello项目
1、首先建立Hello项目,同时建立Maven约定的目录结构和pom.xml文件
Hello
| --src
| -----main
| ----------java
| ----------resources
| -----test
| ---------java
| ---------resources
| --pom.xml
2、编辑项目Hello根目录下的pom.xml,添加如下的代码:
3、在src/main/java/me/gacl/maven目录下新建文件Hello.java
Hello.java的代码如下:
4、在/src/test/java/me/gacl/maven目录下新建测试文件HelloTest.java
HelloTest.java的代码如下:
1package me.gacl.maven;
@shuoshuo293: 我认为,很有可能是jdk的问题,你看看你用的是本地jdk吗。
@小超人1:
@shuoshuo293: 我的意思是你的eclipse上的jdk配置的对吗
@小超人1: 我没有使用eclipse。不过解决了。谢谢!