首页新闻找找看学习计划

Maven学习总结(二)——Maven项目构建过程问题点

0
[待解决问题]

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吗?可以加一下吗?

shuoshuo293的主页 shuoshuo293 | 菜鸟二级 | 园豆:202
提问于:2016-04-25 11:15
< >
分享
所有回答(1)
0

个人认为

第一点: public class 刚才连着了,这可能是你写错了。

第二点:assertEquals("Hello gacl!",results); 很有可能抛出了异常,你看看Hello类里面是否实现equals方法,如果没实现,生成一个equals方法。

墨瞋 | 园豆:477 (菜鸟二级) | 2016-04-25 11:40

我是根据这个文章编写的。请过目!

一、创建Maven项目

1.1、建立Hello项目

  1、首先建立Hello项目,同时建立Maven约定的目录结构和pom.xml文件

    Hello
      | --src
      | -----main
      | ----------java
      | ----------resources
      | -----test
      | ---------java
      | ---------resources
      | --pom.xml

  2、编辑项目Hello根目录下的pom.xml,添加如下的代码:

复制代码
1<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 3<modelVersion>4.0.0</modelVersion> 4<groupId>me.gacl.maven</groupId> 5<artifactId>Hello</artifactId> 6<version>0.0.1-SNAPSHOT</version> 7<name>Hello</name> 8 9<!--添加依赖的jar包-->10<dependencies>11<!--项目要使用到junit的jar包,所以在这里添加junit的jar包的依赖-->12<dependency>13<groupId>junit</groupId>14<artifactId>junit</artifactId>15<version>4.9</version>16<scope>test</scope>17</dependency>1819</dependencies>20</project>
复制代码

  3、在src/main/java/me/gacl/maven目录下新建文件Hello.java

  Hello.java的代码如下:

复制代码
1package me.gacl.maven; 23publicclass Hello { 45public String sayHello(String name){ 6return "Hello "+name+"!"; 7 } 8 }
复制代码

  4、在/src/test/java/me/gacl/maven目录下新建测试文件HelloTest.java  

  HelloTest.java的代码如下:

 

1package me.gacl.maven;

2//导入junit的包 3import org.junit.Test; 4imports tatic junit.framework.Assert.*; 5 6public class HelloTest { 7 8 @Test 9public void testHello(){ 10 Hello hello = new Hello(); 11 String results = hello.sayHello("gacl"); 12 assertEquals("Hello gacl!",results); 13 } 14 }
复制代码
支持(0) 反对(0) shuoshuo293 | 园豆:202 (菜鸟二级) | 2016-04-25 11:54

@shuoshuo293: 我认为,很有可能是jdk的问题,你看看你用的是本地jdk吗。

支持(0) 反对(0) 墨瞋 | 园豆:477 (菜鸟二级) | 2016-04-25 13:57

@小超人1: 

支持(0) 反对(0) shuoshuo293 | 园豆:202 (菜鸟二级) | 2016-04-25 14:57

@shuoshuo293: 我的意思是你的eclipse上的jdk配置的对吗

支持(0) 反对(0) 墨瞋 | 园豆:477 (菜鸟二级) | 2016-04-25 14:59

@小超人1: 我没有使用eclipse。不过解决了。谢谢!

支持(0) 反对(0) shuoshuo293 | 园豆:202 (菜鸟二级) | 2016-04-25 17:59
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册