在FHIR项目中执行mvn jetty:run命令失败求助
我是FHIR Server新手,代码来自hapi-fhir-jpaserver-starter仓库,在Ubuntu 20.04(LTS)上安装时执行mvn jetty:run出现编译失败。
环境信息
Maven版本信息:
Apache Maven 3.6.3 Maven home: /usr/share/maven Java version: 17.0.5, vendor: Private Build, runtime: /usr/lib/jvm/java-17-openjdk-amd64 Default locale: en, platform encoding: UTF-8 OS name: "linux", version: "5.15.0-50-generic", arch: "amd64", family: "unix"
错误日志
执行mvn jetty:run时的错误输出:
[INFO] Scanning for projects... [WARNING] The project ca.uhn.hapi.fhir:hapi-fhir-jpaserver-starter:war:6.2.1 uses prerequisites which is only intended for maven-plugin projects but not for non maven-plugin projects. For such purposes you should use the maven-enforcer-plugin. See https://maven.apache.org/enforcer/enforcer-rules/requireMavenVersion.html [INFO] [INFO] ------------< ca.uhn.hapi.fhir:hapi-fhir-jpaserver-starter >------------ [INFO] Building HAPI FHIR JPA Server - Starter Project 6.2.1 [INFO] --------------------------------[ war ]--------------------------------- [INFO] [INFO] >>> jetty-maven-plugin:9.4.48.v20220622:run (default-cli) > test-compile @ hapi-fhir-jpaserver-starter >>> [INFO] [INFO] --- maven-enforcer-plugin:3.0.0:enforce (enforce-maven) @ hapi-fhir-jpaserver-starter --- [INFO] [INFO] --- jacoco-maven-plugin:0.8.8:prepare-agent (default-prepare-agent) @ hapi-fhir-jpaserver-starter --- [INFO] argLine set to -javaagent:/root/.m2/repository/org/jacoco/org.jacoco.agent/0.8.8/org.jacoco.agent-0.8.8-runtime.jar=destfile=/root/hapi-fhir-jpaserver-starter/target/jacoco.exec,excludes=ca/uhn/fhir/model/dstu2/**/*.class:ca/uhn/fhir/jpa/rp/r5/*.class:ca/uhn/fhir/jpa/rp/r4/*.class:ca/uhn/fhir/jpa/rp/r4b/*.class:ca/uhn/fhir/jpa/rp/dstu3/*.class:ca/uhn/fhir/jpa/rp/dstu2/*.class,dumponexit=true [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ hapi-fhir-jpaserver-starter --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 3 resources [INFO] [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ hapi-fhir-jpaserver-starter --- [INFO] Changes detected - recompiling the module! [INFO] Compiling 31 source files to /root/hapi-fhir-jpaserver-starter/target/classes [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 12.158 s [INFO] Finished at: 2022-11-21T15:39:38Z [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project hapi-fhir-jpaserver-starter: Compilation failure -> [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
目前日志仅提示编译失败,未给出具体错误点,按以下步骤逐步排查:
获取详细编译错误
执行命令mvn jetty:run -e,输出完整堆栈跟踪,能直接看到哪个类、哪行代码编译出错,这是定位问题的核心。修正Java版本编译配置
HAPI FHIR 6.2.1支持Java 11+,但maven-compiler-plugin 3.8.1默认编译规则可能与Java 17不兼容。在项目pom.xml的<build>下的<plugins>中,添加或修改编译器配置:<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>11</source> <target>11</target> <encoding>UTF-8</encoding> </configuration> </plugin>若坚持使用Java 17,建议将maven-compiler-plugin升级至3.10.1及以上版本。
清理缓存后重新编译
执行mvn clean jetty:run,清除之前的编译缓存,避免旧文件干扰新编译过程。检查依赖完整性
执行mvn dependency:resolve,确认所有依赖已正确下载。若存在依赖缺失或损坏,删除本地仓库对应目录(如/root/.m2/repository/ca/uhn/fhir)后重新执行命令。处理prerequisites警告
虽然该警告不是编译失败的直接原因,但可优化配置避免后续潜在问题:移除pom.xml中的<prerequisites>标签,替换为maven-enforcer-plugin规则:<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <version>3.0.0</version> <executions> <execution> <id>enforce-maven</id> <goals> <goal>enforce</goal> </goals> <configuration> <rules> <requireMavenVersion> <version>3.6.0</version> </requireMavenVersion> </rules> </configuration> </execution> </executions> </plugin>
内容的提问来源于stack exchange,提问作者Dejavu79

