spring-boot-maven-plugin not pulling in dependent classes into jar - spring

Im having a problem with the spring-boot-maven-plugin whereby it is not including the dependent classes in the resulting jar file.
In the docs, it states that dependencies with scope provided will be included in the jar file, but I cant get it to include them.
I have a project with 2 sub-modules: model and restServer. In the model module, I want to use swagger to codegen based on an openApi input model. The resulting classes are put in a jar file: model/target/rest-model-0.0.1-SNAPSHOT.jar.
In the restServer module, I have the Spring RestController and Application java code, and want to "pull in" the model classes into the resulting jar file: restServer/target/rest-server-0.0.1-SNAPSHOT.jar with the spring-boot-maven-plugin builder, but its not including anything from the model sub-module.
The entire project structure and pom files are listed below.
How can I get the spring-boot-maven-plugin to pull in the class files from the model sub-module, effectively creating a "fat" self-contained jar?
Project Structure
project-root/
pom.xml # parent pom
model/
pom.xml
src/main/openApi/model.json
target/
generated-sources/* (package: com.me.rest.model.*)
rest-model-0.0.1-SNAPSHOT.jar
restServer/
pom.xml
src/main/java/com/me/rest/
controller/Controller.java
Application.java
Parent 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>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
</parent>
<groupId>com.me</groupId>
<artifactId>rest-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>rest</name>
<packaging>pom</packaging>
<description>Swagger codegen for Spring Rest Server sandbox project</description>
<scm>
<connection>scm:git:git#github.com:swagger-api/swagger-codegen.git</connection>
<developerConnection>scm:git:git#github.com:swagger-api/swagger-codegen.git</developerConnection>
<url>https://github.com/swagger-api/swagger-codegen</url>
</scm>
<prerequisites>
<maven>2.2.0</maven>
</prerequisites>
<modules>
<module>model</module>
<module>restServer</module>
</modules>
</project>
model/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>
<groupId>com.kontron</groupId>
<artifactId>rest-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>com.kontron</groupId>
<artifactId>rest-model</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies> ... </dependencies>
<build>
<plugins>
<!-- Swagger codegen plugin -->
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration> ... </configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
restServer/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>
<groupId>com.kontron</groupId>
<artifactId>rest-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>rest-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>com.kontron</groupId>
<artifactId>rest-model</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>provided</scope> <!-- Notice scope is provided -->
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.1.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Update: adding resulting META-INF/MANIFEST.MF:
Manifest-Version: 1.0
Implementation-Title: rest-server
Implementation-Version: 0.0.1-SNAPSHOT
Built-By: bjohnson
Implementation-Vendor-Id: com.me
Spring-Boot-Version: 2.1.2.RELEASE
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.me.rest.Application
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Created-By: Apache Maven 3.5.4
Build-Jdk: 1.8.0_144
Implementation-URL: https://projects.spring.io/spring-boot/#/spring-bo
ot-starter-parent/rest-parent/rest-server

The dependencies are placed in BOOT-INF\lib\ of the repackaged JAR file.
This path will be added to the classpath of you Spring Boot Application.

Related

Create EAR Project With SpringBoot module

I need to create an EAR file to be deployed on JBoss EAP 7. I considered to build a project structure like the following:
- rootproject
-- ear (ear)
-- web (war)
Therefore for the rootproject I have created a new Simple Maven project (using Eclipse 06/2020), with the following .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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>jboss_test</groupId>
<artifactId>jboss_test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>jboss_ear_test</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.11.RELEASE</version>
</parent>
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>ear</module>
<module>web</module>
</modules>
</profile>
</profiles>
</project>
Therefore, inside it, I have created a SpringBoot 2.2.11 project (WEB) with the following .pom.xml:
....
....
<parent>
<artifactId>jboss_test</artifactId>
<groupId>jboss_test</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>web</artifactId>
<packaging>war</packaging>
<name>web-test</name>
<description>Spring Boot JBOSS</description>
.... // some dependencies
And a Maven module used the ear with the following .pom.xml:
....
....
<parent>
<artifactId>jboss_test</artifactId>
<groupId>jboss_test</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>ear</artifactId>
<packaging>ear</packaging>
<name>ear-test</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.6</version>
<configuration>
<finalName>JBOSS-TEST_EAR</finalName>
<version>6</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<modules>
<webModule>
<groupId>jboss_test</groupId>
<artifactId>web</artifactId>
<bundleFileName>JBOSS-TEST.war</bundleFileName>
<contextRoot>/TEST</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
When I try to build the project from its root I obtain the following error:
Artifact[war:jboss_test:web] is not a dependency of the project
Can you help me to find out whats wrong??
Thank you
Thanks a lot to #khmarbaise for his response, I solved as follows:
Creating rootproject as Simple Maven project, .pom.xml:
<groupId>it.coding.jboss.deployment</groupId>
<artifactId>jbdeployment</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.11.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<modules>
<module>ear-test</module>
<module>web-test</module>
</modules>
Creating ear-test as Maven module, .pom.xml:
<parent>
<groupId>it.coding.jboss.deployment</groupId>
<artifactId>jbdeployment</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>ear-test</artifactId>
<packaging>ear</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.6</version>
<configuration>
<finalName>TEST-EAR</finalName>
<version>6</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<modules>
<webModule>
<groupId>it.coding.jboss.deployment</groupId>
<artifactId>web-test</artifactId>
<bundleFileName>WEB-TEST.war</bundleFileName>
<contextRoot>/WEB-TEST</contextRoot>
</webModule>
</modules>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<manifestEntries>
<Implementation-Title>JBOSS-TEST</Implementation-Title>
<Implementation-Version>1.0</Implementation-Version>
<Implementation-Vendor>CODING</Implementation-Vendor>
<Built-By></Built-By>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>it.coding.jboss.deployment</groupId>
<artifactId>web-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
Creating web-test as SpringBoot 2.2.11 project, .pom.xml:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>it.coding.jboss.deployment</groupId>
<artifactId>jbdeployment</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>web-test</artifactId>
<packaging>war</packaging>
<name>web-test</name>
<description>Spring Boot JBOSS</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
// dependencies
</dependencies>
...
...
</project>
Maven build goes fine and EAR is created.. Than I would like to ask one more thing: do you think I have to define all the dependecies inside my ear-test pom?? Also those of the web-test project related to Spring, Hibernate etc.. ?
Thanks a lot

Artifact[ejb:MoGEMSEJB:MoGEMSEJB] is not a dependency of the project error when adding Maven module

I am converting a Java EE project to a Maven project using IBM Rational Application Developer (RAD) which is based on Eclipse. IBM's instructions say to add the web project as a module in the EAR project but I am getting the error "Artifact[war:MoGEMS_WEB:MoGEMS_WEB] is not a dependency of the project." when I update the Maven project. I have included MoGEMS_WEB as a dependency and it is listed as a dependency when I click on the Dependencies tab in the EAR pom.xml file. The EAR pom file is:
<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>
<groupId>MoGEMSApp</groupId>
<artifactId>MoGEMSApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>ear</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10</version>
<configuration>
<version>5</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<security>
<security-role id="SecurityRole_1">
<role-name>Security Role</role-name>
</security-role>
</security>
<modules>
<webModule>
<groupId>MoGEMS_WEB</groupId>
<artifactId>MoGEMS_WEB</artifactId>
<contextRoot>/mogems</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>MoGEMSEJBClient</groupId>
<artifactId>MoGEMSEJBClient</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>MoGEMSEJB</groupId>
<artifactId>MoGEMSEJB</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>MoGEMS_WEB</groupId>
<artifactId>MoGEMS_WEB</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>

Is it possible to create a spring-boot custom parent pom this is also a multi module project?

I would like to know how to set up a parent pom that handles my spring-boot dependencies as well as builds a few client jars.
Parent Project
|- client-jar-1
| |- src/main/java/MyPojo.java
| |- pom.xml (parent super pom? <package> type is jar)
|- pom.xml (parent is spring-boot-starter-parent <package> type is pom)
Child Project
|- pom.xml (parent pom is custom parent-project, includes client-jar-1 as a dependency)
My thought process is the the parent project can handle common dependencies across multiple independent spring applications and also build a few custom client jars or utility jars, that the child project could include at their own discretion.
Here is my first attempt at my pom files:
Parent Project POM
<?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>
<groupId>com.me.spring.boot.parent</groupId>
<artifactId>me-spring-boot-parent</artifactId>
<version>1.0.0.RELEASE</version>
<packaging>pom</packaging>
<modules>
<module>directory_client</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
...
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>9</source>
<target>9</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
client-jar-1 POM
<?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">
<parent>
<artifactId>me-spring-boot-parent</artifactId>
<groupId>com.me.spring.boot.parent</groupId>
<version>1.0.0.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.me.directory.cleint</groupId>
<artifactId>directory-client</artifactId>
<version>1.0.0.RELEASE</version>
<packaging>jar</packaging>
</project>
Child Project POM
<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>
<groupId>com.me</groupId>
<artifactId>child-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>com.me.spring.boot.parent</groupId>
<artifactId>me-spring-boot-parent</artifactId>
<version>1.0.0.RELEASE</version>
</parent>
<properties>
<flyway.url>jdbc:postgresql://localhost:5432/db</flyway.url>
<flyway.driver>org.postgresql.Driver</flyway.driver>
<flyway.sqlMigrationSeparator>.sql</flyway.sqlMigrationSeparator>
<flyway.sqlMigrationSuffixes></flyway.sqlMigrationSuffixes>
</properties>
</project>
In my Child project when I try and access the client-jar-1 MyPojo I get a compilation error. Here is the expanded dependency from the child project
I can even get my IDE to import the MyPojo class, but there is a problem with the packages and it can't truly resolve the class.
Yes it is possible, in your parent pom add :
<modules>
<module>child1</module>
<module>child2</module>
</modules>
And in your child1 and child2 pom add :
<parent>
<groupId>yourorganization</groupId>
<artifactId>parent</artifactId>
</parent>
The parent pom will contain the spring-boot-starter-parent

How to build an EAR project with EJB and WAR using Maven?

I tried to create EAR Project with EJB and WAR but I have some problem.
I created the main project from the Java EE 6 EAR Archetype:
<dependency>
<groupId>org.codehaus.mojo.archetypes</groupId>
<artifactId>ear-javaee6</artifactId>
<version>1.5</version>
</dependency>
Then I created the EJB module from the Java EE 6 EJB JAR Archetype:
<dependency>
<groupId>org.codehaus.mojo.archetypes</groupId>
<artifactId>ejb-javaee6</artifactId>
<version>1.5</version>
</dependency>
And then I created the second module from the Javax Faces WAR Archetype:
<dependency>
<groupId>javax.faces</groupId>
<artifactId>javax.faces-war-archetype</artifactId>
<version>2.2</version>
</dependency>
Then I added dependencies to main pom.xml:
<!-- Define the versions of your ear components here -->
<dependencies>
<dependency>
<groupId>QCforCC-main</groupId>
<artifactId>QCforCC-ejb</artifactId>
<version>1.0-SNAPSHOT</version>
<type>ejb</type>
</dependency>
<dependency>
<groupId>QCforCC-main</groupId>
<artifactId>QCforCC-war</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
And then I tried to build the project - using maven clean and instal .
But I have an error:
[ERROR] The projects in the reactor contain a cyclic reference: Edge between 'Vertex{label='QCforCC-main:QCforCC-war:1.0-SNAPSHOT'}' and 'Vertex{label='QCforCC-main:QCforCC-ejb:1.0-SNAPSHOT'}' introduces to cycle in the graph QCforCC-main:QCforCC-ejb:1.0-SNAPSHOT --> QCforCC-main:QCforCC-war:1.0-SNAPSHOT --> QCforCC-main:QCforCC-ejb:1.0-SNAPSHOT - [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectCycleException
Process finished with exit code 1
And in EAR pom.xml I have:
<modules>
<module>QCforCC-ejb</module>
<module>QCforCC-war</module>
</modules>
<packaging>pom</packaging>
But if I change <packaging>pom</packaging> to <packaging>ear</packaging>
IDEA show error in popup:
Some problems were encountered while processing the POMs:
[WARNING] 'build.plugins.plugin.(groupId:artifactId)' must be unique but found duplicate declaration of plugin org.apache.maven.plugins:maven-ear-plugin # line 41, column 21
[ERROR] 'packaging' with value 'ear' is invalid. Aggregator projects require 'pom' as packaging. # line 12, column 16
I highly suggest that you understand how multi-module builds work. The Sonatype book has a great chapter describing in great detail.
To build an EAR with an EJB and a WAR, you actually need three modules, for the EJB, WAR and EAR. The parent POM just holds everything together and has a packaging type of POM.
So the parent pom.xml should look like this:
<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>
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>simple-parent</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<name>Multi Chapter Simple Parent Project</name>
<modules>
<module>ejb-module</module>
<module>war-module</module>
<module>ear-module</module>
</modules>
</project>
Then, each of the child POMs would look like this:
ejb-module/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>org.sonatype.mavenbook.multi</groupId>
<artifactId>simple-parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>ejb-module</artifactId>
<packaging>ejb</packaging>
</project>
war-module/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>org.sonatype.mavenbook.multi</groupId>
<artifactId>simple-parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>war-module</artifactId>
<packaging>war</packaging>
<name>simple-webapp Maven Webapp</name>
<dependencies>
<dependency>
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>ejb-module</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
ear-module/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>org.sonatype.mavenbook.multi</groupId>
<artifactId>simple-parent</artifactId>
<version>1.0</version>
</parent>
<artifactId>ear-module</artifactId>
<packaging>ear</packaging>
<name>EAR module</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10.1</version>
<configuration>
<ejbModule>
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>ejb-module</artifactId>
<bundleFilename>ejb-module.jar</bundleFilename>
</ejbModule>
<webModule>
<groupId>org.sonatype.mavenbook.multi</groupId>
<artifactId>war-module</artifactId>
<contextRoot>/foo</contextRoot>
</webModule>
</configuration>
</plugin>
</plugins>
</build>
</project>
parent QCforCC-parent :
<artifactId>QCforCC-parent</artifactId>
<packaging>pom</packaging>
...
...
<modules>
<module>QCforCC-ear</module>
<module>QCforCC-ejb</module>
<module>QCforCC-war</module>
</modules>
QCforCC-ear :
<artifactId>QCforCC-ear</artifactId>
<packaging>ear</packaging>
...
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<version>5</version>
<displayName>XXXXXXXX</displayName>
<modules>
<webModule>
<moduleId>WebModule_XXX</moduleId>
<groupId>${project.groupId}</groupId>
<artifactId>>QCforCC-war</artifactId>
<contextRoot>XXXXXXXX</contextRoot>
</webModule>
<jarModule>
<groupId>${project.groupId}</groupId>
<artifactId>QCforCC-ejb</artifactId>
</jarModule>
</modules>
</configuration>
</plugin>
</plugins>

Autowiring of Spring Data Repo fails with Maven Skinny war option

My question is similar to this one posted a while ago
The autowiring of Spring Data Repos fail when the external libraries are in EAR's lib folder.
The wiring works fine when all jars are included in WEB-INF/lib.
I tried setting the 'skinnyWar' to false but this is duplicating the jars in both EAR and WAR.
The application uses Spring Batch Admin 1.2.2 and Spring Data 1.1 with Spring 3.2.2 based.
Maven Version used is 3.3. The runtime is Websphere 7.x
I have another application that works perfectly fine with skinnywar set to true - this uses spring-ws, spring-data 4.0.x version.
The WAR POM
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>batchadmin-web</artifactId>
<parent>
<groupId>com.xyz.interfaces</groupId>
<artifactId>batch-parent</artifactId>
<version>1.0.BUILD-SNAPSHOT</version>
<relativePath>../batch-parent/pom.xml</relativePath>
</parent>
<packaging>war</packaging>
<name>Batch Admin Interface Web</name>
<dependencies>
<!-- Application specific jars/modules Not included for brevity-->
</dependencies>
<build>
<finalName>springbatch-admin</finalName>
<outputDirectory>${project.basedir}\src\main\webapp\WEB-INF\classes</outputDirectory>
<testOutputDirectory>${project.basedir}\src\main\webapp\WEB-INF\classes</testOutputDirectory>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
<packagingExcludes>WEB-INF/lib/spring-beans*.jar</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
The EAR POM content:
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>batchadmin-ear</artifactId>
<parent>
<groupId>com.xyz.interfaces</groupId>
<artifactId>batch-parent</artifactId>
<version>1.0.BUILD-SNAPSHOT</version>
<relativePath>../batch-parent/pom.xml</relativePath>
</parent>
<packaging>ear</packaging>
<name>Batch Admin Interface</name>
<dependencies>
<dependency>
<groupId>com.xyz.interfaces</groupId>
<artifactId>batchadmin-web</artifactId>
<type>war</type>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<finalName>SpringBatchEAR</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<skinnyWars>true</skinnyWars>
<defaultLibBundleDir>lib/</defaultLibBundleDir>
<modules>
<webModule>
<groupId>com.xyz.interfaces</groupId>
<artifactId>batchadmin-web</artifactId>
<contextRoot>/springbatch-admin</contextRoot>
<bundleFileName>springbatch-admin.war</bundleFileName>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
Update: Since the EAR has only one Web module, used 'Single class loader for application' for 'WAR class loader policy' in the Websphere. This way, I am able to make this work.
I would like to know how to make this work without changing the classloader option as this might not be preferred when multiple web modules are present.

Resources