Java学习笔记之一:打包报错解决Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test

学Java打包时报错

...
Tests in error: 
  testAddEmployee(com.xxxx.oa.organ.service.EmployeeServiceTest): Failed to load ApplicationContext

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.223 s
[INFO] Finished at: 2021-11-27T20:44:05+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project oa-organ: There are test failures.
[ERROR] 
[ERROR] Please refer to E:\Develop\eclipse\workspace\oa-organ\target\surefire-reports for the individual test results.
[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


 

看了一下主要错误就是这一句:Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project

明显就是plugins这个执行不了,

网上找了好几个办法都搞不定,发现为一个解决办法就是更改pom.xml文件

在build里面增加如下代码:(其中这段<plugins></plugins>中间是新增的)

<build>
  <resources>
  			<resource>
  				<directory>src/main/java</directory>
  				<includes>
  					<include>**/*.xml</include>
  				</includes>
  				<filtering>true</filtering>
  			</resource>
  			<resource>
  				<directory>src/main/resources</directory>
  				<includes>
  					<include>**/*.xml</include>
  					<include>**/*.properties</include>
  				</includes>
  				<filtering>true</filtering>
  			</resource>
  </resources>
  <plugins>
     <plugin>  
        <groupId>org.apache.maven.plugins</groupId>  
        <artifactId>maven-surefire-plugin</artifactId>  
        <version>2.4.2</version>  
        <configuration>  
          <skipTests>true</skipTests>  
        </configuration>  
    </plugin>  
  </plugins>
</build>

改完后重跑

结果如下


...
[INFO] Downloaded from aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/maven-plugin-descriptor/2.0/maven-plugin-descriptor-2.0.jar (33 kB at 21 kB/s)
[INFO] Downloaded from aliyun: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/maven-monitor/2.0/maven-monitor-2.0.jar (7.6 kB at 4.6 kB/s)
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ oa-organ ---
[INFO] Building jar: E:\Develop\eclipse\workspace\oa-organ\target\oa-organ-1.0.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  10.065 s
[INFO] Finished at: 2021-11-27T21:43:13+08:00
[INFO] ------------------------------------------------------------------------

打包成功!

每日学一点Java,争取年底Java能达到初级水平

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值