HockChai Lim
HockChai Lim

Reputation: 1713

Maven - optional dependencies not being included in WEB-INF/lib

I've a maven war module that have several optional dependencies declared in pom.xml. In eclipse, those options dependencies are showing as part of the build path, which is what I expected. But during packaging of war file, maven is not including those dependencies in the WEB-INF/lib folder, which is not correct according to maven doc: https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html. Any idea why that is the case?

Below is the complete pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
    <artifactId>dhive</artifactId>
    <groupId>com.boss</groupId>
    <version>1.0</version>
</parent>

<artifactId>Boss</artifactId>
<packaging>war</packaging>

<dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>uk.com.robust-it</groupId>
        <artifactId>cloning</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>net.sf.jt400</groupId>
        <artifactId>jt400</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>com.oracle</groupId>
      <artifactId>ojdbc14</artifactId>
        <optional>true</optional>
    </dependency>       
    <dependency>
        <groupId>net.sourceforge.jtds</groupId>
        <artifactId>jtds</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>com.qoppa</groupId>
      <artifactId>jPDFProcess</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>com.lowagie</groupId>
        <artifactId>itext</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>com.arch</groupId>
      <artifactId>multivalent</artifactId>
        <optional>true</optional>
    </dependency>       
    <dependency>
      <groupId>com.arch</groupId>
      <artifactId>multivalentArch</artifactId>
        <optional>true</optional>
    </dependency>   
    <dependency>
      <groupId>org.jpedal</groupId>
      <artifactId>jpedal</artifactId>
        <optional>true</optional>
    </dependency>   
    <dependency>
      <groupId>com.arch</groupId>
      <artifactId>invoiceTool</artifactId>
        <optional>true</optional>
    </dependency>   
    <dependency>
       <groupId>com.sun</groupId>
       <artifactId>tools</artifactId>
       <version>1.6.0</version>
       <scope>system</scope>
       <systemPath>${env.JAVA_HOME}/lib/tools.jar</systemPath>
     </dependency>                  
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ejb-plugin</artifactId>
            <version>2.5</version>
            <executions>
                <execution>
                    <id>BossClient</id>
                    <configuration>
                        <ejbVersion>3.1</ejbVersion>
                        <generateClient>true</generateClient>
                        <clientIncludes>
                            <clientInclude>/com/**</clientInclude>
                        </clientIncludes>
                    </configuration>
                    <goals>
                        <goal>ejb</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Upvotes: 2

Views: 1530

Answers (2)

HockChai Lim
HockChai Lim

Reputation: 1713

Created an issue to Maven WAR Plugin for this, https://issues.apache.org/jira/browse/MWAR-351.

To get around this issue, I ended up have to removed the

<optional>true</optional> 

from the ejb war module for it to work. For all other projects/Modules that needs the ejb-client from this war module, I ended up have to do exclusion to avoid its dependencies from being added to those projects/modules (See below).

  <dependency>
    <groupId>com.boss</groupId>
    <artifactId>Boss</artifactId>
    <version>1.0</version>
    <type>ejb-client</type>
    <exclusions>
        <exclusion>
            <groupId>*</groupId>
            <artifactId>*</artifactId>
        </exclusion>
    </exclusions>       
</dependency>

Upvotes: 1

Amogh
Amogh

Reputation: 4573

I guess you need to change you plugin in pom.xml try adding following plugin

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
            </manifest>
          </archive>
        </configuration>
      </plugin>

Upvotes: 0

Related Questions