Spring Boot application is not executable - java

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

Related

Vaadin + Spring Boot Production mode build with a runtime error: Failed to determine 'npm' tool

UPDATE ON THE SOLUTION
This bug seems to have been the cause of the problem: https://github.com/vaadin/flow/issues/6657
While the fix is rolled out the marked answer can be used as a workaround
Background
I'm in the process of creating a dockerized, Spring Boot + Vaadin flow based portal for my IoT project.
Problem
The portal works well running from my machine in Vaadin's development mode, with npm installed, but I can't seem to get the right setup for creating a lightweight deployment jar that already contains all the generated front end components.
When I'm running the service in a Docker container, I get the error that it cannot find npm but I assume that it shouldn't be needed for a production deployment
at com.vaadin.flow.server.startup.DevModeInitializer.initDevModeHandler(DevModeInitializer.java:327)
at com.vaadin.flow.spring.VaadinServletContextInitializer$DevModeServletContextListener.contextInitialized(VaadinServletContextInitializer.java:323)
... 46 common frames omitted
Caused by: com.vaadin.flow.server.ExecutionFailedException:
Failed to determine 'npm' tool.
Please install it either:
- by following the https://nodejs.org/en/download/ guide to install it globally
- or by running the frontend-maven-plugin goal to install it in this project:
$ mvn com.github.eirslett:frontend-maven-plugin:1.7.6:install-node-and-npm -DnodeVersion="v12.13.0"
Docker file without npm:
FROM openjdk:11-jre-slim
ARG PROJECT
ARG SERVICE_PORT
ARG JAR_FILE
EXPOSE ${SERVICE_PORT}
RUN mkdir /${PROJECT}
WORKDIR /${PROJECT}
ADD target/${JAR_FILE} ./app.jar
CMD ["java","-jar","app.jar"]
pom.xml (updated!)
<?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.2.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.tlvlp</groupId>
<artifactId>iot-portal</artifactId>
<version>0.0.2</version>
<name>iot-portal</name>
<description>tlvlp IoT server portal</description>
<properties>
<java.version>11</java.version>
<vaadin.version>14.0.12</vaadin.version>
<dockerfile.maven.version>1.4.13</dockerfile.maven.version>
<flow.server.prod.version>2.0.17</flow.server.prod.version>
<!-- DOCKER IMAGE ARGS -->
<docker.project.repository>tlvlp/iot-portal</docker.project.repository>
<service.port>8600</service.port>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-bom</artifactId>
<version>${vaadin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>prod</id>
<properties>
<activatedProperties>prod</activatedProperties>
<vaadin.productionMode>true</vaadin.productionMode>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-server-production-mode</artifactId>
<version>${flow.server.prod.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>flow-maven-plugin</artifactId>
<version>${flow.server.prod.version}</version>
<executions>
<execution>
<goals>
<goal>build-frontend</goal>
<goal>copy-production-files</goal>
<goal>package-for-production</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>${dockerfile.maven.version}</version>
<executions>
<execution>
<id>prod</id>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
</execution>
</executions>
<configuration>
<repository>${docker.project.repository}</repository>
<tag>${project.version}</tag>
<tag>latest</tag>
<buildArgs>
<PROJECT>${project.groupId}.${project.artifactId}</PROJECT>
<SERVICE_PORT>${service.port}</SERVICE_PORT>
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>dev</id>
<properties>
<activatedProperties>dev</activatedProperties>
<vaadin.productionMode>false</vaadin.productionMode>
</properties>
</profile>
</profiles>
</project>
application.properties
spring.profiles.active=#activatedProperties#
application-prod.properties
vaadin.compatibilityMode=false
vaadin.servlet.productionMode=true
I appreciate any guidance :)
All the code can be found on the master branch of the project's public repository: https://github.com/tlvlp/iot-portal
I've finally managed to figure out the solution to the problem.
It was a correct assumption that npm is not required to run the production application.
What wasn't clear from even the official guide that although adding the following property to the prod build profile does populate to the built jar file, but
in itself does NOT trigger Vaadin to run in production mode (at least not together with SpringBoot):
<vaadin.productionMode>true</vaadin.productionMode>
Solution:
What ended up solving the problem is to assign the value of the same parameter in the SpringBoot properties file as well.
Then it started to use the assets generated using npm in build time.
Here is the application.properties file (shared by both dev and prod properties files).
spring.profiles.active=#spring.activatedProperties#
vaadin.productionMode=#vaadin.productionMode#
vaadin.compatibilityMode=false
Here is the complete and updated and working 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 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.2.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.tlvlp</groupId>
<artifactId>iot-portal</artifactId>
<version>0.0.2</version>
<name>iot-portal</name>
<description>tlvlp IoT server portal</description>
<properties>
<java.version>11</java.version>
<vaadin.version>14.0.12</vaadin.version>
<dockerfile.maven.version>1.4.13</dockerfile.maven.version>
<flow.server.prod.version>2.0.17</flow.server.prod.version>
<!-- DOCKER IMAGE ARGS -->
<docker.project.repository>tlvlp/iot-portal</docker.project.repository>
<service.port>8600</service.port>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-bom</artifactId>
<version>${vaadin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>prod</id>
<properties>
<spring.activatedProperties>prod</spring.activatedProperties>
<vaadin.productionMode>true</vaadin.productionMode>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-server-production-mode</artifactId>
<version>${flow.server.prod.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>flow-maven-plugin</artifactId>
<version>${flow.server.prod.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-frontend</goal>
<goal>build-frontend</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>${dockerfile.maven.version}</version>
<executions>
<execution>
<id>prod</id>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
</execution>
</executions>
<configuration>
<repository>${docker.project.repository}</repository>
<tag>${project.version}</tag>
<tag>latest</tag>
<buildArgs>
<PROJECT>${project.groupId}.${project.artifactId}</PROJECT>
<SERVICE_PORT>${service.port}</SERVICE_PORT>
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>dev</id>
<properties>
<spring.activatedProperties>dev</spring.activatedProperties>
<vaadin.productionMode>false</vaadin.productionMode>
</properties>
</profile>
</profiles>
</project>
As I have recently had the same struggle I have the following solution. The easiest way I found to have Java and Nodejs/NPM was to install it to the java base image. This will not be a small docker image. mvn clean package -Pproduction the vaadin root directory. Then edit the Dockerfile to include the installation like so: https://gitlab.com/snippets/1913782
Then build and run the image. Build time and image size will increase a lot. I would love to see some suggestions or additional progress made on this process. Coming from Vaadin8 into 14 has created numerous headaches with having to learn why non-Java things are broken.

Package Not Found Maven Compile Error on Mvn Clean Install

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.

Why does maven plugins show error when spring dependency is added

I was trying to create a maven project and add spring boot dependencies later, but i kept getting error highlights on maven plugins. Here below is the screenshot:
Maven Projects screenshot from intellij
And my POM file contents:
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>org.springframework</groupId>
<artifactId>gs-producing-web-service</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
</parent>
<properties>
<java.version>1.8</java.version>
</properties>
<repositories>
<repository>
<id>java.net</id>
<url>http://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>
<dependencies>
<!-- tag::springws[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
</dependency>
<!-- end::springws[] -->
<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>
<!-- tag::xsd[] -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>${project.basedir}/src/main/resources/</schemaDirectory>
<outputDirectory>${project.basedir}/src/main/java</outputDirectory>
<clearOutputDir>false</clearOutputDir>
</configuration>
</plugin>
<!-- end::xsd[] -->
</plugins>
</build>
May be you have just added the dependencies in your pom.xml file but they are not in your local maven repository. For this purpose you have build/rebuild the project. Once you successfully build the project those dependencies will add to your local repository and will not show these error.
Have you built successfully already? If still there are errors, then might be other issue.

how to spring-boot:run on root pom.xml from multi-module project

I have a multi-module project with Spring Boot.
My root pom.xml only contains 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>com.something</groupId>
<artifactId>my-application</artifactId>
<version>0.1.0</version>
<packaging>pom</packaging>
<modules>
<module>library</module>
<module>application</module>
</modules>
</project>
My spring-boot-maven-plugin is on application module as shown 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.something.tcc</groupId>
<artifactId>my-application-application</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.7.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<jsf.version>2.2.11</jsf.version>
</properties>
<dependencies>
<!-- use this for automatic hot deployment on code changes -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</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>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
</project>
So today, from my root directory, I have to execute my app like this:
mvn spring-boot:run -pl application
If I try mvn spring-boot:run, I receive the error:
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.7.RELEASE:run (default-cli) on project my-application-library: Unable to find a suitable main class, please add a 'mainClass' property -> [Help 1]
I'd like to know what I need to do in order to be able to execute exactly the following command in my root directory:
mvn spring-boot:run
EDIT: as per comment's suggestion I tried moving configuration from application module to root pom.xml, but I still receive the same error:
<?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.something</groupId>
<artifactId>my-application</artifactId>
<version>0.1.0</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.7.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<!-- The main class to start by executing java -jar -->
<start-class>com.something.tcc.Main</start-class>
</properties>
<modules>
<module>library</module>
<module>application</module>
</modules>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>
</project>
Thanks
To address this issue you only need to change configuration in spring-boot-maven-plugin in pom.xml.
Considering you have a spring boot multi-module project your project structure should be something like this
spring-boot-projcet
├─service
└─webapp
The straightforward and the simplest example which I have found was the project which was provided by Burkhard Graves
https://github.com/drahkrub/spring-boot-multi-module
To solve your problem add changes to pom.xml in parent module
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
Add chnages to pom.xml in webapp module
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
With this setup the usual mvn clean spring-boot:run is possible in the root directory of the project.
you can define your main class with either start-class property or mainClass configuration xml tag in your pom.xml
Find the description here.

Spring Boot MVC Multi-Module Executeable jar

I have a multimodule project, build with spring boot 1.1.7
The structure is
+ parent
+ import
+ web
+ backend
My Parent Module will include kind of microservices, what I want to manage from my parent (dependencies what all use) and so on. In import/backend there is my batch business logic, in web there is a mvc application, from where I can start batch job.
In Eclipse everything works fine for me, I can start the application from the Application.java file and application works.
Now I wanted to execute that application by executing executable jar file, but I get following error message when try starting from console.
java -jar application.jar
Kein Hauptmanifestattribut in application.jar
The jar is very small only 5kb, I didn't find any jars of 3 party dependencies in jar package.
The Pom of Web-Module is like follows:
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>at.company.bbsng</groupId>
<artifactId>bbsng-import</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>
<artifactId>bbsng-import-web</artifactId>
<name>bbsng-import-web</name>
<packaging>jar</packaging>
<properties>
<start-class>at.company.bbsng.dataimport.Application</start-class>
</properties>
<dependencies>
<!-- APPLICATION -->
<dependency>
<groupId>at.company.bbsng</groupId>
<artifactId>bbsng-import-backend</artifactId>
<version>${parent.version}</version>
</dependency>
<!-- SPRING ... -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-logging</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
</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>
Pom of Import Module is:
<project>
<parent>
<groupId>at.company.bbsng</groupId>
<artifactId>bbsng</artifactId>
<version>0.1.0-SNAPSHOT</version>
</parent>
<artifactId>bbsng-import</artifactId>
<name>bbsng-import</name>
<packaging>pom</packaging>
<modules>
<module>backend</module>
<module>web</module>
</modules>
</project>
And Pom of Parent is:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>at.company.bbsng</groupId>
<artifactId>bbsng</artifactId>
<version>0.1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>bbsng</name>
<description>BBS Next Generation Application Prototype</description>
<properties>
<java-version>1.8</java-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.springframework.boot-version>1.1.7.RELEASE</org.springframework.boot-version>
</properties>
<modules>
<!-- <module>backend</module> -->
<!-- <module>business</module> -->
<module>import</module>
<!-- <module>infra</module> -->
<!-- <module>log</module> -->
<!-- <module>rest</module> -->
</modules>
<dependencyManagement>
<dependencies>
<!-- SPRING-BOOT ... -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<type>pom</type>
<version>${org.springframework.boot-version}</version>
<scope>import</scope>
</dependency>
<!-- JAVAX ... -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<!-- COMMONS ... -->
...
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.5</version>
<configuration>
<tagBase>
svn://svn.int.company.at/stmlf-repository/prototype/bbsng/tags
</tagBase>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>external</id>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>**/*custom*</exclude>
<exclude>**/custom/*</exclude>
</excludes>
</resource>
</resources>
</build>
</profile>
</profiles>
</project>
If you need further information please ask. Hope you can help me.
Thank you very much.
Finally I found solution. The magic keyword is repackage, see link http://docs.spring.io/spring-boot/docs/1.1.7.RELEASE/maven-plugin/usage.html
So I only need spring-boot-maven-plugin in my web module configured with repackage goal:
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
Then all dependencies are packed in executeable jar file and is startable from console.
I hope it helps for people who face same issue.

Categories