Maven 多模块 EAR - 不添加子模块
Maven Multi Module EAR - Not adding child modules
我有一个基于 wildfly-jakartaee8-with-tools 原型的 Maven 多模块项目 (Jakarta EE 8),部署在 Wildly 26 上并使用 maven-ear-plugin (3.2.0)
这是项目结构
-WebApp.ear
-Web-entities.jar
-Web-ejb.jar
-Web-web.war
-Web-mobile.war
-Web-api.war
这里是Web-ear 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 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.webapp</groupId>
<artifactId>WebApp</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>Web-ear</artifactId>
<packaging>ear</packaging>
<name>Web - ear</name>
<description>This is the EAR POM file</description>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>Web-entities</artifactId>
<type>ejb</type>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>Web-ejb</artifactId>
<type>ejb</type>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>Web-web</artifactId>
<type>war</type>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>Web-mobile</artifactId>
<type>war</type>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>Web-api</artifactId>
<type>war</type>
</dependency>
</dependencies>
<build>
<finalName>${project.parent.artifactId}</finalName>
<plugins>
<!--EAR plugin: format of output file -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>${version.ear.plugin}</version>
<configuration>
<!-- Tell Maven we are using Jakarta EE -->
<version>8</version>
<displayName>Web-ear</displayName>
<generateApplicationXml>true</generateApplicationXml>
<initializeInOrder>true</initializeInOrder>
<!-- Use Jakarta EE ear libraries as needed. Jakarta EE ear libraries
are in easy way to package any libraries needed in the ear, and automatically
have any modules (EJB-JARs and WARs) use them -->
<defaultLibBundleDir>lib</defaultLibBundleDir>
<unpackTypes>war</unpackTypes>
<modules>
<ejbModule>
<groupId>${project.groupId}</groupId>
<artifactId>Web-entities</artifactId>
<bundleFileName>Web-entities.jar</bundleFileName>
</ejbModule>
<ejbModule>
<groupId>${project.groupId}</groupId>
<artifactId>Web-ejb</artifactId>
<bundleFileName>Web-ejb.jar</bundleFileName>
</ejbModule>
<webModule>
<groupId>${project.groupId}</groupId>
<artifactId>Web-web</artifactId>
<contextRoot>/webapp</contextRoot>
<bundleFileName>Web-web.war</bundleFileName>
</webModule>
<webModule>
<groupId>${project.groupId}</groupId>
<artifactId>Web-mobile</artifactId>
<contextRoot>/mobile</contextRoot>
<bundleFileName>Web-mobile.war</bundleFileName>
</webModule>
<webModule>
<groupId>${project.groupId}</groupId>
<artifactId>Web-api</artifactId>
<contextRoot>/api</contextRoot>
<bundleFileName>Web-api.war</bundleFileName>
</webModule>
</modules>
</configuration>
</plugin>
<!-- The WildFly plug-in deploys your ear to a local WildFly / JBoss EAP container.
Due to Maven's lack of intelligence with EARs we need to configure
the WildFly Maven plug-in to skip deployment for all modules. We then enable
it specifically in the ear module. -->
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
但是当我构建生成的 application.xml 不包括任何子模块。
如果我将 generateApplicationXml
设置为 false,然后使用指定的模块手动创建 application.xml,它仍然不会在输出 EAR 中添加子模块。但是如果我在 ear pom 中的模块依赖项上设置 <scope>compile</scope>
它确实包括它们 - 但这对我来说似乎是错误的,因为我看到的所有示例都使用 <scope>provided</scope>
?
我可以看到 Maven 正在正确构建每个子模块,它们存在于子模块的 /target 输出文件夹中,但它只是没有将它们添加到 EAR 输出中,我只是得到一个带有 meta 的空 EAR -信息
我发现这个问题的原因是在父项目 pom.xml
子依赖项被标记为 <scope>provided</scope>
从而阻止了子模块被打包,删除这个修复了问题
我有一个基于 wildfly-jakartaee8-with-tools 原型的 Maven 多模块项目 (Jakarta EE 8),部署在 Wildly 26 上并使用 maven-ear-plugin (3.2.0)
这是项目结构
-WebApp.ear
-Web-entities.jar
-Web-ejb.jar
-Web-web.war
-Web-mobile.war
-Web-api.war
这里是Web-ear 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 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.webapp</groupId>
<artifactId>WebApp</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>Web-ear</artifactId>
<packaging>ear</packaging>
<name>Web - ear</name>
<description>This is the EAR POM file</description>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>Web-entities</artifactId>
<type>ejb</type>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>Web-ejb</artifactId>
<type>ejb</type>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>Web-web</artifactId>
<type>war</type>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>Web-mobile</artifactId>
<type>war</type>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>Web-api</artifactId>
<type>war</type>
</dependency>
</dependencies>
<build>
<finalName>${project.parent.artifactId}</finalName>
<plugins>
<!--EAR plugin: format of output file -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>${version.ear.plugin}</version>
<configuration>
<!-- Tell Maven we are using Jakarta EE -->
<version>8</version>
<displayName>Web-ear</displayName>
<generateApplicationXml>true</generateApplicationXml>
<initializeInOrder>true</initializeInOrder>
<!-- Use Jakarta EE ear libraries as needed. Jakarta EE ear libraries
are in easy way to package any libraries needed in the ear, and automatically
have any modules (EJB-JARs and WARs) use them -->
<defaultLibBundleDir>lib</defaultLibBundleDir>
<unpackTypes>war</unpackTypes>
<modules>
<ejbModule>
<groupId>${project.groupId}</groupId>
<artifactId>Web-entities</artifactId>
<bundleFileName>Web-entities.jar</bundleFileName>
</ejbModule>
<ejbModule>
<groupId>${project.groupId}</groupId>
<artifactId>Web-ejb</artifactId>
<bundleFileName>Web-ejb.jar</bundleFileName>
</ejbModule>
<webModule>
<groupId>${project.groupId}</groupId>
<artifactId>Web-web</artifactId>
<contextRoot>/webapp</contextRoot>
<bundleFileName>Web-web.war</bundleFileName>
</webModule>
<webModule>
<groupId>${project.groupId}</groupId>
<artifactId>Web-mobile</artifactId>
<contextRoot>/mobile</contextRoot>
<bundleFileName>Web-mobile.war</bundleFileName>
</webModule>
<webModule>
<groupId>${project.groupId}</groupId>
<artifactId>Web-api</artifactId>
<contextRoot>/api</contextRoot>
<bundleFileName>Web-api.war</bundleFileName>
</webModule>
</modules>
</configuration>
</plugin>
<!-- The WildFly plug-in deploys your ear to a local WildFly / JBoss EAP container.
Due to Maven's lack of intelligence with EARs we need to configure
the WildFly Maven plug-in to skip deployment for all modules. We then enable
it specifically in the ear module. -->
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
但是当我构建生成的 application.xml 不包括任何子模块。
如果我将 generateApplicationXml
设置为 false,然后使用指定的模块手动创建 application.xml,它仍然不会在输出 EAR 中添加子模块。但是如果我在 ear pom 中的模块依赖项上设置 <scope>compile</scope>
它确实包括它们 - 但这对我来说似乎是错误的,因为我看到的所有示例都使用 <scope>provided</scope>
?
我可以看到 Maven 正在正确构建每个子模块,它们存在于子模块的 /target 输出文件夹中,但它只是没有将它们添加到 EAR 输出中,我只是得到一个带有 meta 的空 EAR -信息
我发现这个问题的原因是在父项目 pom.xml
子依赖项被标记为 <scope>provided</scope>
从而阻止了子模块被打包,删除这个修复了问题