Maven 多模块 EAR - 不添加子模块
我有一个 Maven 多模块项目(Jakarta EE 8),基于 Wildly 26 上部署的 wildfly-jakartaee8-with-tools 原型,并使用 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中的模块依赖项上设置
它确实包含它们 - 但这对我来说似乎是错误的,因为我看到的所有示例都使用 < ;范围>提供
?
我可以看到 Maven 正在正确构建每个子模块,并且它们存在于子模块的 /target 输出文件夹中,但它只是没有将它们添加到 EAR 输出中,我只是得到一个带有元信息的空 EAR
I have a Maven multi-module project (Jakarta EE 8) based on the wildfly-jakartaee8-with-tools archetype being deployed on Wildly 26 and using the maven-ear-plugin (3.2.0)
This is the project structure
-WebApp.ear
-Web-entities.jar
-Web-ejb.jar
-Web-web.war
-Web-mobile.war
-Web-api.war
Here is the 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>
But when I build the generated application.xml does not include any of the child modules.
If I set generateApplicationXml
to false, then manually create the application.xml with the modules specified it still does not add the child modules in the output EAR. but if I set <scope>compile</scope>
on the module dependancies in the ear pom it does include them - but this seems wrong to me as all the examples I see uses <scope>provided</scope>
?
I can see that Maven is building each child module correctly and they are present in the /target output folder of the sub-module but its just not adding them to the EAR output, I just get an empty EAR with meta-info
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现造成这种情况的原因是在项目父
pom.xml
中,子依赖项被标记为provided
,从而阻止子模块正在打包,删除此解决了问题I found that the cause of this was in the project parent
pom.xml
the child dependancies were labeled with<scope>provided</scope>
thus preventing the child modules from being packaged, removing this fixed the issue