I am having an issue with Maven and would need your help to resolve it. I have three Spring Boot projects A, B, and C. In project A, there's a main class annotated with @SpringBootApplication. Project A requires a bean of type X, and both B and C initialize a bean of this type.
For architectural reasons, I need one project that uses A and B, and another project that uses A and C. Therefore, I've set up two Maven projects, each with an empty Java codebase, and a pom that imports:
- The dependencies of A and B
- The dependencies of A and C
<?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>
<groupId>group</groupId>
<artifactId>testAandB</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>17</java.version>
</properties>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>group</groupId>
<artifactId>A</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>group</groupId>
<artifactId>B</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
<mainClass>group.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
When I run "mvn install," the project compiles successfully. However, when I try to execute it using "java -jar," I encounter the following error: Error: Could not find or load the main class group.Main Caused by: java.lang.ClassNotFoundException: group.Main
Am I doing something wrong? How can I resolve this issue?
Thank you in advance.