提问人:user3788903 提问时间:11/3/2023 最后编辑:user3788903 更新时间:11/9/2023 访问量:37
使用 open liberty-maven-plugin 时如何设置委派 parentLast?
How can I set a delegation parentLast when using open liberty-maven-plugin?
问:
我有两个应用程序需要将类加载器设置为 delegation=“parentLast”。
一方面,我有一个不需要在它们上开发的应用程序(称为 sites.ear),我只是按原样使用它,所以我不需要在我的 IDE 中集成这个 EAR。因此,我直接在我的服务器 .xml 上配置了这个应用程序。
另一方面,我有一个名为“博客”的应用程序,我正在开发。如果我在服务器.xml中设置以下行,它可以正常工作,但是如果我这样做,我不能使用liberty-maven-plugin(从IDE启动应用程序)。如果我尝试使用 IntelliJ 启动应用程序,那么它会部署两次代码,一次来自服务器 .xml,另一次来自插件 (mvn liberty:run)
<application id="app-blog" location="C:\Code\app-blog\target\app-blog.ear" name="wem-app-blog" type="ear">
<classloader commonLibraryRef="global" delegation="parentLast"></classloader>
</application>
这是我在我的应用博客中配置的pom.xml
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>3.6</version>
<configuration>
<installDirectory>C:\wlp-webProfile8-21.0.0.12\wlp</installDirectory>
<jvmOptionsFile>C:\wlp-webProfile8-21.0.0.12\wlp\usr\servers\defaultServer\jvm.arguments.txt</jvmOptionsFile>
</configuration>
</plugin>
这是我的服务器.xml
<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">
<library id="global">
<fileset dir="C:\sdk\libs-classpath" includes="*.jar"/>
</library>
<!-- Enable features -->
<featureManager>
<feature>webProfile-8.0</feature>
</featureManager>
<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint id="defaultHttpEndpoint" host="*" httpPort="9080" httpsPort="9443"/>
<!-- Automatically expand WAR files and EAR files -->
<applicationManager autoExpand="true"/>
<application id="sites" location="C:\sdk\websphere\sites.ear" name="sites" type="ear">
<classloader commonLibraryRef="global" delegation="parentLast"></classloader>
</application>
<!-- Default SSL configuration enables trust for default certificates from the Java runtime -->
<ssl id="defaultSSLConfig" trustDefaultCerts="true" />
</server>
我还尝试以全局方式将类加载器配置为parentLast,但它不起作用。
基本上,我想使用集成到我的 IDE IntelliJ 的开放自由服务器,并且我想使用 IDE 启动和停止服务器。现在,我无法使用类加载器parentLast从IDE启动。
有没有办法与IDE集成,将类加载器部署到parentLast?
任何想法或建议都是值得赞赏的。
谢谢
答:
溶液:
使用与应用程序存档的“基本名称”匹配的“位置”来配置应用程序,例如:
<application id="app-blog" location="app-blog.ear" name="wem-app-blog" type="ear">
<classloader commonLibraryRef="global" delegation="parentLast"/>
</application>
(注意:如果要部署工件以在文件名中包含版本,则可能需要调整此设置,可以在服务器 .xml 中添加版本或使用“stripVersion”配置参数)。
解释
Liberty Maven/Gradle 插件努力为通过插件部署的应用程序自动生成部署配置(直接通过 liberty-maven-plugin 的 'deploy' 目标,或作为 'run' 或 'dev' 目标的一部分进行部署)。
However, this can cause problems if you need to provide your own non-default configuration (for something like parent-last classloading) if your configuration does not align with the configuration generated by the Liberty Maven/Gradle plugins. The plugin can end up treating your config as if it were config for a different app, and think it needs to go ahead and generate its own config, and now you have two configs for one app, and only one has the correct attributes, customizations, etc.
NOTE: I would also try this on the latest liberty-maven-plugin version (v3.9) since we've had some fixes in this area over the past years.
评论