Running and compile Spring Boot Multi Module Project - java

I have a Spring Boot Multi Module Project (up vote a basic SpringBoot app. using Spring Initializer, embedded Tomcat, Thymeleaf template engine)
Here the pom of the parent application:
<?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>1.5.3.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.tdk-cloud</groupId>
<artifactId>tdk-cloud</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>tdk-core</module>
<module>tdk-batch</module>
<module>tdk-web</module>
</modules>
..
Here 1 of the libraries:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.tdk-cloud</groupId>
<artifactId>tdk-cloud</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.tdk.core</groupId>
<artifactId>tdk-core</artifactId>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
...
and here another module
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.tdk-cloud</groupId>
<artifactId>tdk-cloud</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.tdk.web</groupId>
<artifactId>tdk-web</artifactId>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.tdk.core</groupId>
<artifactId>tdk-core</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
...
But when I run mvn spring-boot:run in the com.tdk.web module I got this error:
[ERROR] Failed to execute goal on project tdk-web: Could not resolve dependencies for project com.tdkcloud.web:tdk-web:jar:0.0.1-SNAPSHOT: Could not find artifact com.tdkcloud.core:tdk-core:jar:0.0.1-SNAPSHOT -> [Help 1]

Error clearly says
Could not find artifact com.tdkcloud.core:tdk-core:jar:0.0.1-SNAPSHOT
first build tdk-core module, to make it available in your maven repo.
after that build tdk-web module.

Related

Duplicate jars in Java 11 causing below error

We are upgrading project from Java 8 to Java 11, and facing the below error:
The package javax.xml.namespace is accessible from more than one module: <unnamed>, java.xml
Apparently, this is due to same package which is existing in another jar file is creating a problem. In order to fix this issue, we have excluded the jar time temporarily and it is working fine.
Is there a way that we can ignore this error without removing the transient dependencies. Since we have 200+ services and excluding from each service is a mammoth effort.
My pom.xml as below:
<?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>
<groupId>com.xyz</groupId>
<artifactId>test</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<mule.version>3.9.0</mule.version>
<mule.tools.version>1.2</mule.tools.version>
<apikit.version>3.9.0</apikit.version>
<munit.version>1.1.0</munit.version>
<mule.munit.support.version>3.7.1</mule.munit.support.version>
<java.version>11</java.version>
<junit.version>4.9</junit.version>
<jackson.version>2.8.5</jackson.version>
<httpcore.version>4.4.5</httpcore.version>
<spring.version>4.3.2.RELEASE</spring.version>
</properties>
<build>
<finalName>somename</finalName>
</build>
</project>

How to solve this maven multi module dependency issue? It's not importing from local m2 after installing

I have a project with two modules in that. The parent POM looks like this:
<?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>org.example</groupId>
<artifactId>bc</artifactId>
<packaging>pom</packaging>
<version>1.3-SNAPSHOT</version>
<modules>
<module>njoy</module>
<module>api</module>
</modules>
</project>
The njoy module POM looks like this:
<?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>bc</artifactId>
<groupId>org.example</groupId>
<version>1.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>njoy</artifactId>
<packaging>jar</packaging>
</project>
The api module POM looks like this:
<?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>bc</artifactId>
<groupId>org.example</groupId>
<version>1.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>api</artifactId>
<packaging>jar</packaging>
</project>
I have done mvn clean install for the parent POM so that it gets into my local m2 repository.
Now i want to use this project as a dependency in another project(say experiments) by providing it as dependency.
These are the folders created in my m2 repo.
This is my other project where i am using it as a dependency, and the POM for it looks like this:
<?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>org.example</groupId>
<artifactId>experiments</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>bc</artifactId>
<version>1.3-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.example</groupId>
<artifactId>klk</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
But it cannot find the multi-module project artifact, where there is another dependency which is a single module project(klk) and there is no issue.
Please help. What am i missing here?
Thanks in advance!!
The artifact bc is just a pom with some modules. It cannot be used as a dependency. You probably thought you can reference "all artifacts" by referencing the parent POM. This is not possible.
The artifacts njoy and api are jars -- they can be used as a dependency of another project.

Parent version defined in parent

I have done the following structure of poms:
foo/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>
<groupId>com.foo</groupId>
<artifactId>art-foo</artifactId>
<packaging>pom</packaging>
<version>${global.project.version}</version>
<properties>
<global.project.version>1.0.0.0</global.project.version>
</properties>
<modules>
<module>bar</module>
</modules>
foo/bar/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>
<groupId>com.foo.bar</groupId>
<artifactId>art-bar</artifactId>
<packaging>pom</packaging>
<parent>
<groupId>com.foo</groupId>
<artifactId>art-foo</artifactId>
<version>${global.project.version}</version>
</parent>
The problem is that when I do the mvn clean install it makes the build successfully, and I don't understand why it works and how the son is able to get the parent version property defined in the parent.
Additionally, I've tried editing the parent pom to the following:
<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>com.foo</groupId>
<artifactId>art-foo</artifactId>
<packaging>pom</packaging>
<version>1.0.0.0</version>
<properties>
<global.project.version>1.0.0.0</global.project.version>
</properties>
<modules>
<module>bar</module>
</modules>
and this time I get an error when compiling, which is normal as the son cannot see the parent property.
The question is, why the first build finishes successfully and the second doesn't?
Thanks.

Maven child project build failure

Data-Layer pom file:
<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.ehr</groupId>
<artifactId>parentEHR</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>Data-Layer</artifactId>
<packaging>jar</packaging>
</project>
Core-layer pom file
<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.ehr</groupid>
<artifactId>parentEHR</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>Core-Layer</artifactId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.ehr</groupId>
<artifactId>Data-Layer</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Error:
Failed to execute goal on project Core-Layer: Could not resolve dependencies for project com.ehr:Core-Layer:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at com.ehr:Data-Layer:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for com.ehr:Data-Layer:jar:0.0.1-SNAPSHOT: Could not find artifact com.ehr:parentEHR:pom:0.0.1-SNAPSHOT -> [Help 1]
The above error occurs.
Can any one help me?
You need to make sure that modules (children) are defined in the parent as well as modules defining their parent in their own pom.
In parent pom:
<modules>
<module>Core-Layer</module>
<module>Data-Layer</module>
</modules>
And then start a build from within the parent folder, which will build the modules in order (from top to bottom).
If your dependency project is built successfully, then maven should find that artifact in your local repository, when building the current project(in your case, 'Core-Layer').
Make sure you build your data-layer project with the command 'mvn install'.This command updates your local repository with the artifact.
If the maven build is successful, verify the artifact in your local repository.(Generally ${current_user}.m2\repositories\com\ehr).
If the artifact of data-layer is available there, then maven will read it from there, whenever you are referring it with that artifact id.
Assuming parentEHR is your parent project and Core-Layer, Data-Layer are child projects of the same. pom.xml of each should look like as:
parentEHR - 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ehr</groupId>
<artifactId>parentEHR</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>../Data-Layer</module>
<module>../Core-Layer</module>
</modules>
</project>
Core-Layer - 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ehr</groupId>
<artifactId>Core-Layer</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>com.ehr</groupId>
<artifactId>parentEHR</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parentEHR</relativePath>
</parent>
</project>
Data-Layer - 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ehr</groupId>
<artifactId>Data-Layer</artifactId>
<packaging>jar</packaging>
<parent>
<groupId>com.ehr</groupId>
<artifactId>parentEHR</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parentEHR</relativePath>
</parent>
</project>

Jar is not getting executed in Maven based project in netbeans

Hi I'm working on project which created in netbeans 8.0.1.
It is created in Maven.Now after completion when try to open created jar its not getting executed.
below is the pom.xml file.
Please advise.
<?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.elitechweb.asm</groupId>
<artifactId>Test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<build>
</build>
</project>
Added maven-install-plugin-2.3.1 jar file. and changes in POM.xml respective jar

Categories