Maven 找不到作为 war 运送的包裹罐

Maven cannot find jars of package shipped as war

我想从一个 java 包中包含(导入)一些 类,该包作为 war 在 Maven 中央存储库中发布,但也有一个 jar包裹。这就是为什么它在 mvn repository 网站上的依赖性 xml 表示为

<dependency>
    <groupId>org.camunda.bpm</groupId>
    <artifactId>camunda-engine-rest</artifactId>
    <version>7.14.0</version>
</dependency>

我在我的 pom 中使用了依赖项,我的代码编译成功。但是当我 运行 mvn clean install 我得到以下错误:

Failure to find org.camunda.bpm:camunda-engine-rest:jar:7.14.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced

此外,当我将类型 war (<type>war</type>) 添加到我的依赖项时,我没有收到上述错误,但现在我的代码无法编译。

很奇怪,因为当我访问https://repo.maven.apache.org/maven2 and navigate to the GAV I can find the jars

您显示的目录中的 JAR 有 classifier.

如果您需要其中之一,则必须将 classifier 添加到依赖项中,例如

<classifier>classes</classifier>

我不了解 Camunda,但我也会查看文档。使用其他方法可能比尝试使用 WAR 的 class 更好。

使用纯 spring 引导“启动器”依赖项时出现问题,它包含 camunda 引擎和 tomcat,因此即使您使用 or 删除 tomcat,它也会继续 运行 在 tomcat 上,因为它已经在 camunda 引擎中。当您尝试创建 war 文件并粘贴到外部的共享 camunda 引擎时,war 将不起作用。这是因为您创建的 war 包含 camunda 引擎和其中的 tomcat,当您粘贴到另一个外部 camunda 引擎时,它会混淆使用哪个 camunda。 请参阅此解决方案:http://javaint4bytes.blogspot.com/2019/11/camunda-spring-boot-with-shared-engine.html

一种可能更好的方法是不引用完整的 WAR 作为依赖项,而是引用您需要的特定 jar。您可以将您在代码中导入的 jar(例如 camunda-engine)添加到您的 POM 而不是完整的 war 文件。这是一个例子:https://github.com/rob2universe/camunda-custom-rest-endpoint/blob/main/custom-endpoint/pom.xml