我有一个使用 maven、spring-boot 并连接到 postresql 数据库的简单项目。当我运行 mvn clean install 时,一切都运行良好,甚至是测试。(我正在用 java 10 编译它)然后我添加一个 module-info.java 将它变成一个 java9 模块。现在,如果我构建它并且我没有 -DskipTests,我会收到以下错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test (default-test) on project birdtree-model-dao: There are test failures.
[ERROR]
[ERROR] Please refer to D:\Programming practice\Mentoring Donna Informatica\birdtree_project\birdtree_java_workspace\birdtree-model-dao\target\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was cmd.exe /X /C ""C:\Program Files\Java\jdk-10.0.1\bin\java" @C:\Users\Manuela\AppData\Local\Temp\surefire16709347194940961814\surefireargs14150574352838310253 C:\Users\Manuela\AppData\Local\Temp\surefire16709347194940961814 2019-05-01T01-23-43_537-jvmRun1 surefire9560741769530673276tmp surefire_08315816585779964257tmp"
[ERROR] Error occurred in starting fork, check output in log
[ERROR] Process Exit Code: 1
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
[ERROR] Command was cmd.exe /X /C ""C:\Program Files\Java\jdk-10.0.1\bin\java" @C:\Users\Manuela\AppData\Local\Temp\surefire16709347194940961814\surefireargs14150574352838310253 C:\Users\Manuela\AppData\Local\Temp\surefire16709347194940961814 2019-05-01T01-23-43_537-jvmRun1 surefire9560741769530673276tmp surefire_08315816585779964257tmp"
[ERROR] Error occurred in starting fork, check output in log
[ERROR] Process Exit Code: 1
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:669)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:282)
...
并且 surefire-reports 文件包含:
# Created at 2019-05-01T00:58:57.663
Error: Could not find or load main class practice\Mentoring
# Created at 2019-05-01T00:58:57.663
Caused by: java.lang.ClassNotFoundException: practice\Mentoring
(听起来有点像问题是文件路径中的空间,对吗?但如果是,我在哪里更正?)
所以,我认为这一定是模块信息的错,因为这是唯一改变的事情。我一直在纠结要放什么。自动生成的一个 Eclipse 似乎是错误的,例如因为它包含测试依赖项,这给了我其他错误。所以我尝试了一下,它目前看起来像这样:
module birdtreeModelDao {
exports mjl.familytree.birdtree;
//requires junit; //eclipse adds this. But I think test dependencies don't belong here, right?
requires spring.boot;
requires spring.boot.autoconfigure; //included this externally by creating new library
//requires spring.boot.test; //eclipse adds this. But it just gives me other errors. And again, it's a test dependency, so surely it shouldn't be here.
requires spring.context;
}
这是我的pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>mjl.familytree</groupId>
<artifactId>birdtree-model-dao</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>birdtree-model-dao</name>
<description>Manuela's family tree program</description>
<repositories>
<repository>
<id>repository.spring.release</id>
<name>Spring GA Repository</name>
<url>http://repo.spring.io/release</url>
</repository>
</repositories>
<properties>
<maven.compiler.source>1.10</maven.compiler.source><!-- 1.12 -->
<maven.compiler.target>1.10</maven.compiler.target><!-- 1.12 -->
<maven.compiler.release>10</maven.compiler.release>
<java.version>10</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.springframework.boot</groupId> -->
<!-- <artifactId>spring-boot-starter-data-rest</artifactId> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.springframework.boot</groupId> -->
<!-- <artifactId>spring-boot-starter-web</artifactId> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.springframework.boot</groupId> -->
<!-- <artifactId>spring-boot-starter-web-services</artifactId> -->
<!-- </dependency> -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<!-- <version>4.12</version> -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- https://stackoverflow.com/questions/50661648/spring-boot-fails-to-run-maven-surefire-plugin-classnotfoundexception-org-apache/50661649#50661649 -->
<!-- Used this to try to prevent "The forked VM terminated without properly saying goodbye" when running with tests and with module-info.java -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
</project>
知道是什么导致了错误吗?