Create EAR Project With SpringBoot module - spring-boot

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

Related

Spring-boot local repository 2.7.5 not working

an attempt to work with local repository of spring-boot project
failing according to intellij, but project is compiling and dependencies exist.
is it possible the all is good , but intellij error flag is wrong ?
<?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 https://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.7.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>project-manager</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>project-manager</name>
<description>project-manager</description>
<properties>
<java.version>11</java.version>
<apache.poi.version>5.2.2</apache.poi.version>
<fasterxml.jackson.version>2.14.1</fasterxml.jackson.version>
</properties>
<dependencies>
... dependencies
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
worked fine with central-repository on parent version 2.7.5
worked fine with local repository on parent 2.3.0-RELEASE
thanks.
in case someone get same issue , solution:
Intellij (v 2021.3.3)
press
"File | Invalidate Caches" fixed the issue.
jetbrain support

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>

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

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.

Run two war instances in the same server.xml config

I've generated two instances of Spring Boot (1.5.10.RELEASE) (war) with different properties (DB),
My question is about to run those two instances with same port but with different context in WebSphere Liberty Core 8.5 ?
My server.xml :
<httpEndpoint id="defaultHttpEndpoint"
host="*"
httpPort="9081"
httpsPort="9443"/>
<!-- A application -->
<webApplication id="A" location="A-0.0.1-SNAPSHOT.war" contextRoot="/interactioncorpcontext-a"/>
<!-- B application -->
<webApplication id = "B" location="B-0.0.1-SNAPSHOT.war" contextRoot="/interactioncorpcontext-b"/>
As result :
**http://hostname:9081/interactioncorpcontext-a**
**http://hostname:9081/interactioncorpcontext-b**
I found a solution is to create an EAR of two war modules :
<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>ear</artifactId>
<packaging>ear</packaging>
<name>${project.artifactId}</name>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>a.b.c</groupId>
<artifactId>AP00959-starter-parent</artifactId>
<version>1.5.10-SNAPSHOT</version>
</parent>
<dependencies>
<!-- Project dependencies -->
<dependency>
<groupId>a.b.c</groupId>
<artifactId>CCS</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>a.b.c</groupId>
<artifactId>mael</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10.1</version>
<configuration>
<modules>
<webModule>
<groupId>a.b.c</groupId>
<artifactId>CCS1FRD0</artifactId>
<contextRoot>/interactioncorpcontext-ccs</contextRoot>
</webModule>
<webModule>
<groupId>a.b.c</groupId>
<artifactId>mael</artifactId>
<contextRoot>/interactioncorpcontext-mael</contextRoot>
</webModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
</project>
Also to disable jmx endpoints :
endpoints:
jmx:
enabled: false

Get war module when running the parent maven project

Is there a way to run a war module automatically when I run the parent project?
To make it clear, I did three separate maven project (db, core and presentation), then I made a parent project which include the 3 projects mentioned before.
I'd like to get the presentation module running when I run the parent project.
Also, I want to know if it's possible to save the hole work from the parent project to my git account.
<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.project.xxxxxxx</groupId>
<artifactId>parent-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parent-project</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<targetJdk>1.7</targetJdk>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<port>8080</port>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${targetJdk}</source>
<target>${targetJdk}</target>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
</plugins>
</build>
<modules>
<module>../project-db</module>
<module>../project-core</module>
<module>../project-presentation</module>
</modules>
<dependencies>
</dependencies>
</project>
You need to specify the sub-project under tag.
You may refer http://books.sonatype.com/mvnex-book/reference/multimodule-sect-simple-parent.html for example
Your modules should be unter your parent in the file structure. Like
parent-project
pom.xml
project-db
pom.xml
project-core
pom.xml
project-presentation
pom.xml
Then you have to change the parent pom:
<modules>
<module>project-db</module>
<module>project-core</module>
<module>project-presentation</module>
</modules>

Resources