Package Not Found Maven Compile Error on Mvn Clean Install - java

I have a micro-service based application that I am building out locally. I have a situation where micro-service A is depending on micro-service B and as such I have included B in A's pom as a dependency and there are no errors in the code and all of the classes are recognized. However, when I go to do a 'mvn clean install' command on A, I get the error where none of the packages in B are recognized as well as 'Cannot find symbol' for all of the classes from B that I am trying to use in A.
I have tried changing the execution goal of the maven plugin to 'repackage' in the pom of B like:
<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>
I have also confirmed that the JAR file is getting correctly built out to my local maven repository in my .m2 folder and made sure that the classes and code is contained there.
I also have tried breaking down the maven commands into sub-commands instead of just doing a maven clean install
POM for MS A
<?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.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.oz</groupId>
<artifactId>franchise-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>oz-franchise-api</name>
<description>API for FRP</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- SPRING WEB -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- DATABASE/JPA BACKEND -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- USEFUL TOOLS -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- OTHER OZ DEPENDENCIES -->
<dependency>
<groupId>com.oz</groupId>
<artifactId>core-library</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
POM for MS B
<?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.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.oz</groupId>
<artifactId>core-library</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>oz-core-library</name>
<description>The core library for oz</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- SPRING BOOT -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- DATABASE/JPA BACKEND -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- MYSQL DATABASE -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version>
</dependency>
<!-- JAVAX VALIDATION -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<!-- LOMBOK -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</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>
</project>

If your two microservices both need a set of classes, put that classes into a separate (third) jar, build it as normal jar and use it as dependency in both.

Related

Execution default-testResources

I was doing a project at work on a PC there, when I got home I tried to open it on my PC and I ended up encountering two errors in line 5 of the pom.xml file, my PC already gave an error when installing the new ones versions of eclipse, now this is giving error in my work project, I hope someone help me please.
error 1:
Execution default-testResources of goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:testResources failed:
Unable to load the mojo 'testResources' (or one of its required components) from the plugin
'org.apache.maven.plugins:maven-resources-plugin:3.2.0'
(org.apache.maven.plugins:maven-resources-plugin:3.2.0:testResources:default-testResources:process-test-resources)
error 2:
Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources failed:
Unable to load the mojo 'resources' (or one of its required components) from the plugin
'org.apache.maven.plugins:maven-resources-plugin:3.2.0'
(org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources:default-resources:process-resources)
pom.xml file:
<?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.5.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</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>

Spring boot dependency error for some of the dependencies in maven

Below is my 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.java.hackathon</groupId>
<artifactId>com.java.hackathon</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>com.java.hackathon</name>
<url>http://maven.apache.org</url>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.6.0.1398</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- junit 5 -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.0</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Error message i am getting is
For artifact {org.springframework.boot:spring-boot-starter-data-jpa:null:jar}: The version cannot be empty. (org.apache.maven.plugins:maven-resources-
plugin:2.6:testResources:default-testResources:process-test-resources) org.apache.maven.artifact.InvalidArtifactRTException: For artifact
{org.springframework.boot:spring-boot-starter-data-jpa:null:jar}: The version cannot be empty. at
But in most of the cases what I observed most of them wont declare any version for spring-boot-starter-data-jpa and spring-boot-starter-web but i am getting these errors I am getting errors for all the dependencies where i had not declared version
So i want to know how to resolve these errors where version has not been declared or any plugins needed to be downloaded. I am executing the code in eclipse.
Normally you don't declare dependency versions when you have defined a dependencyManagement section in your POM where you centralize all of the dependencies used by all of your modules.
Since your POM does not define a dependencyManagement, you will need to provide the version for each dependency. You can check this sample guide project from Spring Boot, where you will notice that they set a parent in the POM:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
This parent will cause the POM to inherit a dependencyManagement section containing all of the versions of the spring-boot-starter-xx dependencies.
More details: https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-dependency-management

How to build a multi-module Maven project without a main class in one of the modules

I've been trying to find an answer to this issue in similar questions but I still don't know what is causing it.
I have a multi-module maven project and I'm trying to run mvn install or mvn package and I get the following error
[INFO] app ................................................... SUCCESS
[ 1.025 s]
[INFO] module-data ..................................... FAILURE [
0.952 s]
[INFO] module-app ...................................... SKIPPED
[ERROR] Failed to execute goal
org.springframework.boot:spring-boot-maven-plugin:2.1.1.RELEASE:repackage
(repackage) on project project-data: Execution repackage of goal
org.springframework.boot:spring-boot-maven-plugin:2.1.1.RELEASE:repackage
failed: Unable to find main class -> [Help 1]
The project-app module has a java class in the src folder, whereas the project-data module does not have a main class.
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>
<packaging>pom</packaging>
<modules>
<module>project-data</module>
<module>project-app</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>app</name>
<description></description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
project-data 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">
<parent>
<artifactId>app</artifactId>
<groupId>com.example</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>project-data</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<skip>true</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
project-app 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">
<parent>
<artifactId>app</artifactId>
<groupId>com.example</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>project-app</artifactId>
<dependencies>
<dependency>
<artifactId>project-data</artifactId>
<groupId>com.example</groupId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
I have something very similar to the structure of this project (sfg-pet-clinic), however, after downloading and running mvn package, it works fine. I don't see much difference between the pom files of my project and this one so what could I be missing?
Configuration is for older versions of spring.
Remove:
<configuration>
<skip>true</skip>
</configuration>
Instead, add this flag below pom artifactId
<properties>
<spring-boot.repackage.skip>true</spring-boot.repackage.skip>
</properties>
Like so:
<parent>
<artifactId>mc-pet-clinic</artifactId>
<groupId>guru.springframework</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>pet-clinic-data</artifactId>
<properties>
<spring-boot.repackage.skip>true</spring-boot.repackage.skip>
</properties>
...
I would move the entire
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
section from the parent to the module-app module, because that one is the single module which uses the repackage functionality.
Moreower I would delete the plugin section from the module-data too, because there is no need to repackage that module.
Thanks to #wemu on the comments section.
Adding this:
<configuration>
<mainClass> ${your.start.Class}</mainClass>
</configuration>
to the plugin section is required on version 2.1.1.RELEASE of the spring-boot-starter-parent dependency, as long as your class is in another module.
The project sfg-pet-clinic I referred to in my question uses an older version which does not need the <mainClass> configuration
Okay here is how I fixed that.
My Steps were:
Change the packaging of pom.xml file for project-data to pom from
jar (I used overview of Eclipse)
add <type>pom</type> in pom.xml file for project-app for dependency of module-data
<dependency>
<groupId>samee.springframework</groupId>
<artifactId>project-data</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>pom</type>
</dependency>
Then you can run your clean and package/install
I just changed the Spring Boot version in the parent pom.xml from 2.1.1 to 2.0.3 and it works.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
Would be better to make it work in 2.1.1 though, but that's a quick and simple solution.

Spring boot application as dependency

My problem is that I have a multi module maven build where one part is generated by swagger as a spring boot application.
The second module should extend on the code generated and finally started.
When I compile with maven the second project does not find the classes in the generated code. I checked the jar and the class files end up in a BOOT-INF directory when building the jar.
I suspect that this is the problem. What is the best solution to compile my code.
the parent 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>
<parent>
<groupId>com.xxx</groupId>
<artifactId>applications</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<name>project1-connector</name>
<artifactId>project1-connector</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<scm>
<developerConnection>scm:git:ssh://git#xxx.com:7999/bla/project1-java-repo.git</developerConnection>
</scm>
<properties>
<majorVersion>1</majorVersion>
<minorVersion>0</minorVersion>
</properties>
<build>
<plugins>
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
<language>spring</language>
<configurationFile>${project.basedir}/src/main/resources/apiConfig.json</configurationFile>
<output>${project.basedir}/project1-api</output>
<configOptions>
<sourceFolder>src/main/java</sourceFolder>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<modules>
<module>project1-api</module>
<module>project1-backend</module>
</modules>
project1-api generated 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.xxx</groupId>
<artifactId>project1-api</artifactId>
<packaging>jar</packaging>
<name>project1-api</name>
<version>1.0.1</version>
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<springfox-version>2.7.0</springfox-version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<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>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<!--SpringFox dependencies -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<!-- Bean Validation API support -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
</dependencies>
</project>
project1-backend pom.xml
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>com.xxx</groupId>
<artifactId>project1-backend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>project1-backend</name>
<description>Project1 Connection</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>9</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.xxx</groupId>
<artifactId>project1-api</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
As stated here:
https://happilyblogging.wordpress.com/2017/07/31/using-spring-boot-application-as-dependency-in-another-spring-boot-application-project/
The problem is in the generated pom.xml.
If I add the configuration part to the project1-api spring-boot plugin part, it works.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>exec</classifier>
</configuration>
</execution>
</executions>
</plugin>

Spring Boot application is not executable

I am migrating my old Spring setup to Spring Boot 1.5.1.RELEASE.
I'm failing to get an executable .jar, I followed countless examples but my jar fails to become an executable.
It's a multi-module setup so here is my 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.xyz</groupId>
<artifactId>xyz</artifactId>
<name>xyz</name>
<version>1.0.0</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<commons.version>3.5</commons.version>
<guava.version>21.0</guava.version>
</properties>
<modules>
<module>mainApp</module>
<module>module1</module>
<module>module2</module>
..........
</modules>
<dependencyManagement>
<dependencies>
<!-- Spring boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- commons -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<!-- google guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
This is the pom of the mainApp, it is the module that has Application.java which holds main method.
<?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>
<parent>
<artifactId>xyz</artifactId>
<groupId>com.xyz</groupId>
<version>1.0.0</version>
</parent>
<artifactId>mainApp</artifactId>
<groupId>com.xyz.mainApp</groupId>
<packaging>jar</packaging>
<name>mainApp</name>
<dependencies>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Spring Security OAuth2-->
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
</dependency>
<!-- xyz dependencies -->
<dependency>
<groupId>com.xyz.module3</groupId>
<artifactId>module3</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.xyz.module2</groupId>
<artifactId>module2</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<finalName>xyz</finalName>
</build>
</project>
Things that work:
So things work okay when I do mvn clean install in the folder of parent pom.xml and then run mvn spring-boot:run in the mainApp folder
Things that fail:
when I execute java -jar mainApp/target/xyz.jar I get an error like:
no main manifest attribute, in mainApp/target/xyz.jar
if I attempt to run the jar like ./mainApp/target/xyz.jar, well I can't as the file is not an executable, my macOS Sierra terminal shows this for file permissions:
-rw-r--r-- 1 userXYZ staff 37641156 Feb 1 13:14 xyz.jar
If I manually change the permissions to -rwxr--r-- and attempt to run the file I get this gibberish:
/xyz.jar: line 1: PK: command not found
./xyz.jar: line 2: syntax error near unexpected token `)'
./xyz.jar: line 2: ?iAJ META-INF?iAJMETA-INF/MANIFEST.MFu??J?0??y?y??,??nW*???Jb3?F?LI?????qa?n?3???)Mp5&V????ñ^IQ?????ޱ?.#??`?$?{<??7?m6?j܀?W????'????γڎ9?>????RT?͡?V??
G??
3iR?G4???dә?A(̀?z?ϖV]ٷ??T??O>?^??0wy?u?^??S]?iG?2?"???i?$?'
The problem is not how the plugin is configured, but where the plugin is configured.
I have wrapped my plugins with <pluginManagement>, which was causing all the problems, when i removed it all was resolved and worked perfectly
update your build block in pom.xml with following, make sure you are using using Maven 3.2 (or better):
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.1.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
the main class entry is missing in the jar manifesto.
Please modify the boot maven plugin as below:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>${start-class}</mainClass>
<layout>ZIP</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
Plugin info

Categories