【问题标题】:Create EAR Project With SpringBoot module使用 SpringBoot 模块创建 EAR 项目
【发布时间】:2020-11-09 18:28:31
【问题描述】:

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

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

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

<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 项目(WEB),并带有以下.pom.xml

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

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

谢谢

【问题讨论】:

  • 因为消息告诉你这个问题。您没有将 Web 部件定义为 ear 项目的依赖项......除此之外,我强烈建议您从 pom 中删除带有模块的配置文件,这没有任何意义,也没有与模块/配置文件相关的有用信息...
  • 我怎样才能做到这一点??
  • 将依赖项添加到您的 web 模块的 pom 中...
  • 我试了一下,但我得到了更多的错误,你能写两行代码吗?我想创建一个包含我的 web .war 包的 EAR...为什么我必须在 pom of war 项目中声明 ear?
  • 在你的 &lt;artifactId&gt;ear&lt;/artifactId&gt; 模块中定义依赖而不是在战争中.. 战争项目的 pom 中的耳朵也没有..

标签: spring-boot maven ear


【解决方案1】:

非常感谢@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 中定义所有依赖项吗?还有那些与SpringHibernate等相关的web-test项目。?

非常感谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-02
    • 1970-01-01
    相关资源
    最近更新 更多