1

I have an ear module, so composed:

ear ejb web

I'm using maven for managing the package; every module has its own pom.xml

Now, let's say the pom.xml of the ear module is this:

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

.. and this is the pom.xml on the root

    <dependency>
        <groupId>org.burp</groupId>
        <artifactId>some-lib</artifactId>
        <scope>compile</scope>
    </dependency>

When I compile ear, I can see some-lib.jar is either on {root}/lib and myproject-web/WEB-INF/lib.

How can I put all dependencies ONLY on {root}/lib

Fabrizio Stellato
  • 1,727
  • 21
  • 52

2 Answers2

1

You can override the scope of the dependency in the war module, something like:

<dependency>
    <groupId>org.burp</groupId>
    <artifactId>some-lib</artifactId>
    <scope>provided</scope>
</dependency>
J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
0

Maybe the usage of SkinnyWars can be a solution for your case:

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

Code sample from Apache Maven War Plugin

  • This should be a suggested link to the question as comment. –  Oct 14 '21 at 14:58
  • I don't have enough reputation to comment on other people's posts :) – Christopher Pereira Oct 15 '21 at 15:05
  • Hey, welcome to StackOverflow community! You should earn at least 15 reputation to comment on posts. You can earn reputations by editing posts (questions, answers) [read more](https://stackoverflow.com/help/whats-reputation). –  Oct 15 '21 at 15:35