maven, ear package 将依赖项放在 ear 和 web 模块下
maven, ear package put dependencies either under ear and web module
我有一个耳机模块,所以沉着:
耳朵
ejb
网页
我正在使用 maven 来管理包;每个模块都有自己的 pom.xml
现在假设耳机模块的pom.xml是这样的:
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>myproject-ejb</artifactId>
<type>ejb</type>
</dependency>
<!-- Depend on the EJB module and WAR so that we can package them -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>myproject-web</artifactId>
<type>war</type>
</dependency>
<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>
<!-- 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>
<modules>
<!-- Default context root of the web app is /customers-web.
If a custom context root is needed, uncomment the following snippet to
register our War as a web module and set the contextRoot property -->
<!--
<webModule>
<groupId>${project.groupId}</groupId>
<artifactId>customers-web</artifactId>
<contextRoot>/customers</contextRoot>
</webModule>
-->
</modules>
<outputFileNameMapping>@{artifactId}@@{dashClassifier?}@.@{extension}@</outputFileNameMapping>
</configuration>
</plugin>
<!-- The WildFly plug-in deploys your ear to a local 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>
.. 这是根
上的 pom.xml
<dependency>
<groupId>org.burp</groupId>
<artifactId>some-lib</artifactId>
<scope>compile</scope>
</dependency>
当我编译 ear 时,我可以看到一些-lib.jar 在 {root}/lib 和 myproject-web/WEB-INF/lib 上。
如何将所有依赖项仅放在 {root}/lib
你可以覆盖 war 模块中的依赖范围,比如:
<dependency>
<groupId>org.burp</groupId>
<artifactId>some-lib</artifactId>
<scope>provided</scope>
</dependency>
也许使用 SkinnyWars 可以解决您的问题:
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<defaultLibBundleDir>lib/</defaultLibBundleDir>
<skinnyWars>true</skinnyWars>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
的代码示例
我有一个耳机模块,所以沉着:
耳朵 ejb 网页
我正在使用 maven 来管理包;每个模块都有自己的 pom.xml
现在假设耳机模块的pom.xml是这样的:
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>myproject-ejb</artifactId>
<type>ejb</type>
</dependency>
<!-- Depend on the EJB module and WAR so that we can package them -->
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>myproject-web</artifactId>
<type>war</type>
</dependency>
<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>
<!-- 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>
<modules>
<!-- Default context root of the web app is /customers-web.
If a custom context root is needed, uncomment the following snippet to
register our War as a web module and set the contextRoot property -->
<!--
<webModule>
<groupId>${project.groupId}</groupId>
<artifactId>customers-web</artifactId>
<contextRoot>/customers</contextRoot>
</webModule>
-->
</modules>
<outputFileNameMapping>@{artifactId}@@{dashClassifier?}@.@{extension}@</outputFileNameMapping>
</configuration>
</plugin>
<!-- The WildFly plug-in deploys your ear to a local 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>
.. 这是根
上的 pom.xml <dependency>
<groupId>org.burp</groupId>
<artifactId>some-lib</artifactId>
<scope>compile</scope>
</dependency>
当我编译 ear 时,我可以看到一些-lib.jar 在 {root}/lib 和 myproject-web/WEB-INF/lib 上。
如何将所有依赖项仅放在 {root}/lib
你可以覆盖 war 模块中的依赖范围,比如:
<dependency>
<groupId>org.burp</groupId>
<artifactId>some-lib</artifactId>
<scope>provided</scope>
</dependency>
也许使用 SkinnyWars 可以解决您的问题:
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<defaultLibBundleDir>lib/</defaultLibBundleDir>
<skinnyWars>true</skinnyWars>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
的代码示例