在 Eclipse 中为 Liberty 生成的 .ear.xml 是错误的

Generated .ear.xml for Liberty in Eclipse is wrong

有问题的插件

我对可用的 eclipse Liberty 插件有疑问 here on the marketplace。我链接了测试版,但稳定版的行为完全相同。

Maven ear 项目说明

我有一个由多个maven 模块组成的maven 项目。 ear 模块的 pom.xml 看起来像这样。顺便说一下,maven 生成的耳朵看起来还不错。

<?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>

  <artifactId>myear</artifactId>
  <packaging>ear</packaging>

  <name>my ear module</name>

  <dependencies>
    <dependency>
      <groupId>my.groupid</groupId>
      <artifactId>myWARmodule</artifactId>
      <version>${project.version}</version>
      <type>war</type>
      <scope>compile</scope>
      <!-- EJBs are not to be included in the war. -->
        <exclusion>
          <groupId>my.groupid</groupId>
          <artifactId>myEJBmodule</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>my.groupid</groupId>
      <artifactId>myWARmodule</artifactId>
      <version>${project.version}</version>
      <type>pom</type>
      <scope>import</scope>
      <exclusions>
        <exclusion>
          <groupId>my.groupid</groupId>
          <artifactId>myEJBmodule</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <!-- jar module -->
    <dependency>
      <groupId>my.groupid</groupId>
      <artifactId>myAdditionalJarModule</artifactId>
      <version>${project.version}</version>
      <type>jar</type>
    </dependency>

    <!-- EJB module -->
    <dependency>
      <groupId>my.groupid</groupId>
      <artifactId>myEJBmodule</artifactId>
        <type>ejb</type>
    </dependency>

    <!-- API implementation -->
    <dependency>
      <groupId>ch.qos.logback</groupId>
      <artifactId>logback-classic</artifactId>
    </dependency>
    <dependency>
      <groupId>org.ehcache</groupId>
      <artifactId>ehcache</artifactId>
      <version>3.2.0</version>
    </dependency>
    <dependency>
      <groupId>org.jsr107.ri</groupId>
      <artifactId>cache-annotations-ri-cdi</artifactId>
      <version>1.0.0</version>
    </dependency>

  </dependencies>

  <build>
    <finalName>myEarApp</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-ear-plugin</artifactId>
        <version>2.10.1</version>
        <configuration>
          <version>7</version>
          <finalName>myEARApp</finalName>
          <defaultLibBundleDir>lib</defaultLibBundleDir>
          <defaultJavaBundleDir>lib</defaultJavaBundleDir>
          <skinnyWars>true</skinnyWars>

          <modules>
            <!-- Root level modules: WAR and EJBs. -->
            <webModule>
              <groupId>my.groupd</groupId>
              <artifactId>myWARmodule</artifactId>
            </webModule>

            <ejbModule>
              <groupId>my.groupid</groupId>
              <artifactId>myEJBmodule</artifactId>
            </ejbModule>

            <jarModule>
              <groupId>my.groupid</groupId>
              <artifactId>myAdditionalJarModule</artifactId>
              <includeInApplicationXml>true</includeInApplicationXml>
            </jarModule>
          </modules>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

结果耳

生成的 ear 文件结构如下:

myEARApp.ear
- myWarApp.war
   -- (no libs in WEB-INF/lib)
- lib/
  -- (a lot of libs here due to skinny wars)
- myEJBmodule.jar
- myAdditionalJarModule.jar

属性 - Maven 程序集描述符

当我单击 ear 项目并查看 "assembly descriptor" 时,程序集与 ear 文件的布局相匹配,这是正确的。

所以,这很好。

创建自由服务器并添加应用程序

现在,当我在 eclipse 中添加服务器并想要 运行 ear 文件时,我创建了一个 "websphere liberty profile server",版本 17.0.0.2。然后我将 ear 模块添加到服务器,配置应用程序(即应用程序绑定等)。

服务器可以通过在 server/apps 文件夹中生成替换 myEARApp.ear.xml 文件,从工作区 运行 项目。它具有 ear 文件的结构。嗯,它应该有。两周左右以来,myEARApp.ear.xml-文件的结构更像是这样:

myEARApp.ear
- myWarApp.war
   -- a lot of libs from the war module
   -- myEJBmodule.jar
   -- myAdditionalJarModule.jar
- lib/
  -- only a few extra jar modules referenced in ear/pom.xml
  -- missing: logback, ehcache, etc.
- myEJBmodule.jar
- myAdditionalJarModule.jar
- otherDependencyOfmyAdditionalJarModule.jar

糟糕的是,这显然不会 运行 由于可用于注入的重复 bean 和很多 classnotfoundexceptions。

如何解决?

所以,我的问题是:eclipse liberty profile 插件如何生成它的 .ear.xml 文件?为什么它与我在 pom.xml 中配置的布局不同?即使没有瘦身战争和导入范围依赖性,生成的 myEARApp.ear.xml 自由文件也不会改变。

感谢帮助!

看起来 Eclipse M2E 插件不支持 skinnyWars。您可以在错误报告底部尝试变通方法。

https://bugs.eclipse.org/bugs/show_bug.cgi?id=461613

WDT 根据项目属性中的部署程序集设置生成 myEARApp.ear.xml 文件。当项目导入工作区时,Eclipse M2E 插件应该解释 pom.xml 并翻译设置,并根据 pom.xml 文件中的设置在项目属性中设置部署程序集。

您能否检查 EAR 和 Web 模块的项目属性中的“部署程序集”页面,以查看模块是否如您预期的那样正确设置?您可以尝试的另一件事是导出 EAR 文件(当您右键单击 EAR 项目时使用 Export 菜单)。如果导出的项目没有您期望的结构,那么问题是由于 Eclipse M2E 插件没有正确支持 skinnyWars 引起的,正如前面评论的 bugzilla 中提到的那样。

找到解决方案。

我从 eclipse 中删除了很多 jboss 插件,例如 JBoss 开发人员工具、JBoss Hibernate 等

我只保留了几个:

  • CDI 工具
  • Java EE 批量配置工具
  • JMX 控制台
  • Eclipse JDT 编译器的 M2E 连接器
  • Eclipse JDT APT 的 Maven 集成

现在又可以正常工作了。谁会想到呢?此外,它没有出现在任何日志中,为什么 .ear.xml 自由文件的生成被 JBoss Dev Studio 或其他插件损坏。

我希望这对任何其他开发人员有用。