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

标签 java xml eclipse maven websphere-liberty

有问题的插件

我对可用的 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项目并查看“程序集描述符”时,程序集与ear文件的布局相匹配,这是正确的。

所以,这很好。

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

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

服务器可以通过在 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

坏事是,由于可用于注入(inject)的重复 bean 和大量 classnotfoundExceptions,这显然不会运行。

如何解决?

所以,我的问题是: eclipse liberty profile 插件如何生成它的 .ear.xml 文件?为什么它与我在 pom.xml 中配置的布局不同?即使没有 Skinny Wars 和导入作用域依赖,生成的 myEARApp.ear.xml 文件的 liberty 也不会改变。

感谢帮助!

最佳答案

找到了解决方案。

我从eclipse中删除了很多jboss插件,比如JBoss开发者工具,JBoss Hibernate等。

我只保留了一些:

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

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

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

关于java - 在 Eclipse 中为 Liberty 生成的 .ear.xml 是错误的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45629149/

相关文章:

java - 将 xml 从 POST 读取到 http servlet 的推荐/最快方法是什么?

java - 黑莓 json 解析代码示例无法正常工作

iOS-Web服务: Webservice for iOS client

java - 如何在 Java Swing 中抓取鼠标?

java - Servlet JSP 异常/错误处理

java - 如果在 xml 中它是空的,为什么 simplexml 将 NULL 设置为字段?

c - 无法在 Windows 中包含 pthread.h

java - 如何创建美国 map 并自由填充每个州的颜色?

Java 通过接口(interface)向上转型和向下转型

java - XMLStreamReader 和解码 SOAP 消息