Reputation: 743
I am creating a Spring Boot multi module project.. Module A has a dependency on Module B ..
Module A runs fine when I run in exploded form..
mvn spring-boot:run
But I am unable to package the jar along with dependencies so that I can execute it as
java -jar Module-A.jar
Module A pom.xml is below:
<parent>
<artifactId>Module-Test</artifactId>
<groupId>com.module</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>Module-A</artifactId>
<packaging>jar</packaging>
<properties>
<start-class>com.NotifyApp</start-class>
<main.class>com.NotifyApp</main.class>
</properties>
<dependencies>
<dependency>
<groupId>com.module</groupId>
<artifactId>Module-B</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.4.2.RELEASE:repackage (default) on project Module-A: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.4.2.RELEASE:repackage failed: Source must refe r to an existing file
Parent pom.xml
<modelVersion>4.0.0</modelVersion>
<artifactId>Module-Test</artifactId>
<groupId>com.module</groupId>
<version>1.0.0-SNAPSHOT</version>
<modules>
<module>Module-A</module>
<module>Module-B</module>
<module>Module-C</module>
</modules>
<packaging>pom</packaging>
<parent>
<artifactId>Module-Parent</artifactId>
<groupId>com.parent</groupId>
<version>1.0.2</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.module</groupId>
<artifactId>Module-A</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.module</groupId>
<artifactId>Module-B</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.module</groupId>
<artifactId>Module-C</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.module</groupId>
<artifactId>starter-service</artifactId>
<version>${starter.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
Upvotes: 3
Views: 6634
Reputation: 1327
I usually use this plugin https://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-project-dependencies.html for maven, which will put all of the dependency jars into target/dependencies when you run
mvn clean package
Then I copy the jars into a folder (which I usually call lib) and I include lib/* in my classpath. The final run script usually looks like
java -cp lib/*: my.package.MySpringBootMain
Upvotes: 1
Reputation: 3356
Add dependency of module B in module A's pom.xml
<dependencies>
<dependency>
<groupId>com.module</groupId>
<artifactId>Module-B</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Use maven clean compile package install command for module B, to build module B first and then run maven clean compile package on Module A. This will out Module B into Module A.
There is no module A's reference required in Module B's pom.xml
Upvotes: 0
Reputation: 155
you sure know, but you can initialize your project from this link Spring Initializr , it automatically generates the configuration with what you need
Upvotes: -1
Reputation: 4136
Remove the
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
It's not needed.
Upvotes: 0