开发者社区 问答 正文

在maven中使用junit执行install时报错?报错

问题:我的maven中引入了junit

<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.9</version>
			<scope>test</scope>
		</dependency>



然后当我对pom.xml文件执行install的时候就报错了,弄了好几天都没办法,求大神指点一下小弟啊。

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project shiroexample: Compilation failure: Compilation failure:
[ERROR] /E:/workspace/study/shiroexample Maven Webapp/src/main/java/com/shiro/chapter2/LoginLogoutTest.java:[3,17] 程序包org.junit不存在
[ERROR] /E:/workspace/study/shiroexample Maven Webapp/src/main/java/com/shiro/chapter2/LoginLogoutTest.java:[6,10] 找不到符号
[ERROR] 符号:   类 Test
[ERROR] 位置: 类 com.shiro.chapter2.LoginLogoutTest
[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



展开
收起
爱吃鱼的程序员 2020-06-09 13:15:45 614 分享 版权
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    因为你的junit的jar包的scope是test的,但是你的单元测时的代码放到了/src/main/java/里面,这是不对的,应该放到/src/test/java/里面,这些都是有讲究的,你看你的报错信息,里面已经非常明显了噢,这样啊原来,太感谢你了!用于单元测试的类你是不是放到了main里面,应该放到test里面哦
    回复<aclass='referer'target='_blank'>@lavare_z:“[ERROR]/E:/workspace/study/shiroexampleMavenWebapp/src/main/java/“我说的是这个main没有,就是放在类中的,现在重新建了一个工程,没有那个问题了。但是说不定以后还会出现

    写了<spanstyle="font-family:Consolas,"font-size:14px;line-height:15.4px;background-color:#FFFFFF;">程序包org.junit不存在,肯定是不存在,不会骗你的,好好到底有没有正确引入了

    <spanstyle="background-color:#FFFFFF;">也可以用-DskipTests,忽略测试

    好的谢谢啦,我试试。现在重新建了一个工程,没有那个问题了。但是说不定以后还会出现

    2020-06-09 13:16:04
    赞同 展开评论