使用SpringBoot模块创建EAR项目

问题描述

我需要创建一个EAR文件以部署在JBoss EAP 7上。我考虑过要建立一个如下的项目结构:

- rootproject
  -- ear (ear)
  -- web (war)

因此,对于rootproject,我使用以下.pom.xml创建了一个新的Simple Maven项目(使用Eclipse 06/2020):

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>jboss_test</groupId>
 <artifactId>jboss_test</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <packaging>pom</packaging>
 <name>jboss_ear_test</name>

 <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.11.RELEASE</version>
 </parent>

 <profiles>
  <profile>
    <id>default</id>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
    <modules>
        <module>ear</module>
        <module>web</module>
    </modules>
  </profile>
 </profiles>

</project>

因此,在其中,我使用以下SpringBoot 2.2.11创建了一个.pom.xml项目(WEB):

....
....
<parent>
    <artifactId>jboss_test</artifactId>
    <groupId>jboss_test</groupId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>web</artifactId>
<packaging>war</packaging>
<name>web-test</name>
<description>Spring Boot JBOSS</description>

.... // some dependencies

Maven模块将耳朵与以下.pom.xml配合使用:

....
....
<parent>
    <artifactId>jboss_test</artifactId>
    <groupId>jboss_test</groupId>
    <version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>ear</artifactId>
<packaging>ear</packaging>
<name>ear-test</name>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <finalName>JBOSS-TEST_EAR</finalName>
                <version>6</version>
                <defaultLibBundleDir>lib</defaultLibBundleDir>
                <modules>
                    <webModule>
                        <groupId>jboss_test</groupId>
                        <artifactId>web</artifactId>
                        <bundleFileName>JBOSS-TEST.war</bundleFileName>
                        <contextRoot>/TEST</contextRoot>
                    </webModule>
                </modules>
           </configuration>
      </plugin>
   </plugins>
</build>

当我尝试从根目录构建项目时,出现以下错误:

Artifact[war:jboss_test:web] is not a dependency of the project

您能帮我找出问题所在吗?

谢谢

解决方法

非常感谢@khmarbaise的回答,我解决了以下问题:

rootproject创建为简单Maven项目,.pom.xml

<groupId>it.coding.jboss.deployment</groupId>
<artifactId>jbdeployment</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.2.11.RELEASE</version>
  <relativePath/> <!-- lookup parent from repository -->
</parent>

<modules>
 <module>ear-test</module>
 <module>web-test</module>
</modules>

ear-test创建为Maven模块.pom.xml

<parent>
  <groupId>it.coding.jboss.deployment</groupId>
  <artifactId>jbdeployment</artifactId>
  <version>0.0.1-SNAPSHOT</version>
</parent>

<artifactId>ear-test</artifactId>
<packaging>ear</packaging>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <finalName>TEST-EAR</finalName>
                <version>6</version>
                <defaultLibBundleDir>lib</defaultLibBundleDir>
                <modules>
                    <webModule>
                        <groupId>it.coding.jboss.deployment</groupId>
                        <artifactId>web-test</artifactId>
                        <bundleFileName>WEB-TEST.war</bundleFileName>
                        <contextRoot>/WEB-TEST</contextRoot>
                    </webModule>
                </modules>
                <archive>
                    <addMavenDescriptor>false</addMavenDescriptor>
                    <manifestEntries>
                         <Implementation-Title>JBOSS-TEST</Implementation-Title>
                         <Implementation-Version>1.0</Implementation-Version>
                         <Implementation-Vendor>CODING</Implementation-Vendor>
                         <Built-By></Built-By>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>it.coding.jboss.deployment</groupId>
        <artifactId>web-test</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <type>war</type>
    </dependency>
</dependencies>

web-test创建为SpringBoot 2.2.11项目,.pom.xml

<modelVersion>4.0.0</modelVersion>
  <parent>
     <groupId>it.coding.jboss.deployment</groupId>
     <artifactId>jbdeployment</artifactId>
     <version>0.0.1-SNAPSHOT</version>
  </parent>

  <artifactId>web-test</artifactId>
  <packaging>war</packaging>
  <name>web-test</name>
  <description>Spring Boot JBOSS</description>

  <properties>
    <java.version>1.8</java.version>
  </properties>

  <dependencies>
     // dependencies
  </dependencies>
  ...
  ...
</project>

Maven构建正常并且创建了EAR。比我想再问一件事:您认为我必须在ear-test pom内定义所有依赖项吗?还与web-testSpring等相关的Hibernate项目的项目。?

非常感谢

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...