I am new to Springboot and trying to re-create my teachers application, but I get an error when I run
mvn clean package spring-boot:repackage
that says it cannot find main class in backend module. Error message:
[INFO] Root of quiz ....................................... SUCCESS [ 0.386 s]
[INFO] backend ............................................ FAILURE [ 11.162 s]
[INFO] frontend ........................................... SKIPPED [INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE [INFO] -----------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.4.4:repackage (default-cli) on project backend: Execution default-cli of goal org.springframework.boot:spring-boot-maven-plugin:2.4.4:repackage failed: Unable to find main class -> [Help 1]
The @Springbootapplication main class that runs the application is in frontend module. How do I tell the application that? I tried these steps by adding a springgboot-maven-plugin in root pom file with still no luck. I also tried to reduce the number of packages and make the application.class as close as possible to src folder, even though none of these things should matter because it works on my teachers.
Here is my root pom 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
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>quiz</artifactId>
<groupId>org.quiz</groupId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>Root of quiz</name>
<modules>
<module>backend</module>
<module>fronten</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<fs>${file.separator}</fs>
<version.java>11</version.java>
<version.jacoco>0.8.5</version.jacoco>
<!-- FIXME version 1.4.200 breaks tests, eg in JPA-JPQL -->
<version.h2>1.4.197</version.h2>
<version.testcontainers>1.15.1</version.testcontainers>
<version.selenium>3.141.59</version.selenium>
<version.springboot>2.3.5.RELEASE</version.springboot>
<version.junit>5.7.0</version.junit>
<version.junit.platform>1.5.2</version.junit.platform>
<!--
TODO: cannot update to 4.3+ as conflicts of major versioning
of Groovy runtime
-->
<version.surefire-failsafe>3.0.0-M4</version.surefire-failsafe>
<version.hibernate.validator>6.1.0.Final</version.hibernate.validator>
<version.hibernate.core>5.3.7.Final</version.hibernate.core>
<version.javax.el>3.0.0</version.javax.el>
<version.javax.javae.api>8.0.1</version.javax.javae.api>
<jbossTarget>${basedir}/target/downloaded_Wildfly</jbossTarget>
<jbossHome>${jbossTarget}/wildfly</jbossHome>
<!-- When updating this version, must also update Dockerfile using jboss/wildfly
images-->
<version.wildfly>18.0.1.Final</version.wildfly>
</properties>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<!-- SpringBoot BOM -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>${version.springboot}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${version.springboot}</version>
<scope>test</scope>
<!-- Exclude JUnit 4, which is added by default-->
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!--Hibernate-->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${version.hibernate.core}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${version.hibernate.validator}</version>
<scope>provided</scope>
</dependency>
<!-- Database -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.197</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.1.4</version>
</dependency>
<!--Containers, all needed??-->
<dependency>
<!-- Note: this has the other as dependency -->
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId><!--Db-->
<version>${version.javax.el}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.core</groupId>
<artifactId>arquillian-core-api</artifactId>
<version>1.5.0.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly.arquillian</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
<version>2.2.0.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>1.5.0.Final</version>
<!-- make sure it is in test scope -->
<scope>test</scope>
</dependency>
<!-- Junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${version.junit}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${version.junit}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>2.0</version>
<exclusions>
<exclusion>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.joinfaces</groupId>
<artifactId>jsf-spring-boot-starter</artifactId>
<!--
This depends on Spring version, see:
https://github.com/joinfaces/joinfaces
However, SpringBoot 2.1 would require 4.x (eg 4.0.9) here,
but it does not work, whereas 3.2 is fine...
-->
<version>3.2.3</version>
</dependency>
<!--Selenium-->
<dependency>
<!-- used to control a browser for system testing -->
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${version.selenium}</version>
<scope>test</scope>
</dependency>
<dependency>
<!-- used to control a browser for system testing -->
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>${version.selenium}</version>
<scope>test</scope>
</dependency>
<dependency>
<!-- used to control a browser for system testing -->
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>${version.selenium}</version>
<scope>test</scope>
</dependency>
<dependency>
<!-- used to control a browser for system testing -->
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>${version.selenium}</version>
<scope>test</scope>
</dependency>
<dependency>
<!-- used to control a browser for system testing -->
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>${version.selenium}</version>
<scope>test</scope>
</dependency>
<dependency>
<!-- for code coverage -->
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.core</artifactId>
<version>${version.jacoco}</version>
<scope>test</scope>
</dependency>
<dependency>
<!-- To use Docker from tests -->
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>${version.testcontainers}</version>
<scope>test</scope>
</dependency>
<dependency>
<!-- To support JUnit 5 -->
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${version.testcontainers}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>selenium</artifactId>
<version>${version.testcontainers}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<!-- Need to create self-executable uber/fat jars for SpringBoot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${version.springboot}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- Used to download and unpack JBoss/Wildfly automatically before running the
tests-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>process-test-classes</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-dist</artifactId>
<version>${version.wildfly}</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>${jbossTarget}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<!-- Built-in plugin used to compile Java code -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<inherited>true</inherited>
<configuration>
<release>${version.java}</release>
</configuration>
</plugin>
<!-- For running ANT tasks, like renaming files/folders -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
</plugin>
<!--
When unzipping Wildfly, the folder name will contain the version.
This is not good, as then we would need to hardcode such version
in each Arquillian file.
So, we make sure to rename such folder.
Why? If then we change Wildfly version, we only update such value
here in the pom file, and not in every single Arquillian file...
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>Rename Wildfly folder</id>
<phase>process-test-classes</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<move file="${jbossTarget}/wildfly-${version.wildfly}"
tofile="${jbossTarget}/wildfly"
failonerror="false"
/>
</target>
</configuration>
</execution>
</executions>
</plugin>
<!-- this is needed to run integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${version.surefire-failsafe}</version>
<configuration>
<forkCount>1</forkCount>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<rerunFailingTestsCount>3</rerunFailingTestsCount>
<argLine>-Xms512m -Xmx4096m</argLine>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Built-in plugin used to execute unit tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${version.surefire-failsafe}</version>
<configuration>
<forkCount>1</forkCount>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<rerunFailingTestsCount>3</rerunFailingTestsCount>
<argLine>-Xms512m -Xmx2048m</argLine>
</configuration>
</plugin>
<!-- Avoid failing War generation if web.xml is missing, as we ll not
use it in some example modules -->
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<!-- For cloud deployment on Heroku -->
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>2.0.2</version>
</plugin>
<!--code coverage-->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${version.jacoco}</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<phase>initialize</phase>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>default-prepare-agent-integration</id>
<phase>package</phase>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
</execution>
<execution>
<id>default-report-integration</id>
<phase>verify</phase>
<goals>
<goal>report-integration</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Here is the backend module 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>
<version>1.0-SNAPSHOT</version>
<parent>
<artifactId>quiz</artifactId>
<groupId>org.quiz</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>backend</artifactId>
<groupId>org.quiz.backend</groupId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
</dependency>
<!--Springboot, versions are retrieved from springboot BOM (pom) in parent pom-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!--Database-->
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<!-- For code coverage -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>
<!-- Built-in plugin used to execute unit tests, (TODO: tests passes without this
too) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>1</forkCount>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<rerunFailingTestsCount>3</rerunFailingTestsCount>
<!--suppress UnresolvedMavenProperty -->
<argLine>${argLine} -Xms512m -Xmx4096m</argLine>
</configuration>
</plugin>
</plugins>
</build>
</project>
Image of project structure (I was not allowed to post the image here)