我正在使用 liberty-maven-plugin“开发模式”部署一个简单的应用程序,运行
mvn liberty:dev
。
我尝试通过 server.xml 以两种方式自定义我的应用程序配置:
我的应用程序配置似乎被忽略了。
当我点击 server.xml 中指定的上下文根目录下的网页时,出现
Context Root Not Found
错误:“http://localhost:9080/ctx”。
我的应用程序似乎是在另一个上下文根
/demo
上启动,基于工件 ID:
[INFO] [AUDIT ] CWWKT0016I: Web application available (default_host): http://localhost:9080/demo/
[INFO] [ERROR ] CWWKZ0013E: It is not possible to start two applications called demo.
...
[INFO] [WARNING ] CWWKZ0014W: The application demo could not be started as it could not be found at location demo.war.
DescriptorCustomizer
API 相关的 ClassCastException [INFO] [ERROR ] CWWJP9992E: java.lang.ClassCastException: io.openliberty.guides.event.dao.EventHistory incompatible with org.eclipse.persistence.config.DescriptorCustomizer
[INFO] [ERROR ] CWWJP0015E: An error occurred in the org.eclipse.persistence.jpa.PersistenceProvider persistence provider when it attempted to create the container entity manager factory for the jpa-unit persistence unit. The following error occurred: Exception [EclipseLink-28019] (Eclipse Persistence Services - 3.0.3.v202208190922): org.eclipse.persistence.exceptions.EntityManagerSetupException
<project>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<!-- ... -->
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>3.9</version>
<configuration>
<copyDependencies>
<!-- ... -->
</copyDependencies>
</configuration>
<!-- ... -->
<server description="Sample Liberty server">
<featureManager>
<feature>restfulWS-3.0</feature>
<feature>jsonb-2.0</feature>
<feature>jsonp-2.0</feature>
<feature>cdi-3.0</feature>
<feature>persistence-3.0</feature>
</featureManager>
<!-- ... -->
<application location="demo.war" type="war" context-root="/ctx">
<classloader apiTypeVisibility="+third-party" />
</application>
<!-- Derby Library Configuration -->
<library id="derbyJDBCLib">
<fileset dir="${shared.resource.dir}/" includes="derby*.jar" />
</library>
核心问题来自这样一个事实:当应用程序尚未在服务器配置(server.xml 等)中配置时,Liberty Maven(和 Gradle)插件的
deploy
目标(任务)将(默认情况下)生成应用程序配置。 ).
这是“一个功能,而不是一个错误”,但是,当用户尝试为给定应用程序提供配置,而插件计算出此配置对应于一个完全不同的应用程序时,就会出现问题。
如果配置与插件的期望不“匹配”(基于下面详细介绍的
location
属性),liberty-maven-plugin 将继续生成自己的应用程序配置作为“配置 dropin”,尽管用户的在 server.xml 中配置。
充其量,用户配置不会生效,并且可能会出现冲突,导致根本无法工作,就像这个例子一样。
“匹配”基于应用程序
location
属性。
如果我们查看插件生成的配置,我们就会看到问题,生成一个“config dropin”到如下文件中:./target/liberty/wlp/usr/servers/defaultServer/configDropins/defaults/install_apps_configuration_1491924271.xml .
<server>
<webApplication id="demo" location="demo-0.0.1-SNAPSHOT.war" name="demo"/>
</server>
由于这里的
location
属性包含版本,因此与原始 server.xml中配置的
location
属性(不包含版本)不匹配:
<application location="demo.war" type="war" context-root="/ctx">
...
将“位置”与 liberty-maven-plugin 计算值对齐。
要么:
<finalName>
删除版本: <build>
<finalName>${project.artifactId}</finalName>
或
<stripVersion>
配置参数: <plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>3.9</version>
<configuration>
<stripVersion>true</stripVersion>