学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能达到初级水平