Tomash Gombosh
Tomash Gombosh

Reputation: 143

Can not run spring boot application using maven

Cannot run spring boot application using maven. When I run command mvn spring-boot:run I receive: Could not find or load main class src.main.java.com.linkedinSearch.api.SearchApplication, but in the pom.xml I write where is the main class using that example:

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.2.2.RELEASE</version>
                <configuration>
                    <mainClass>src.main.java.com.linkedinSearch.api.SearchApplication</mainClass>
                </configuration>
            </plugin>

I have this project structure:

pom.xml
-src.main.java.linkedinSearch.api
--SearchApplication.java
--config
--controller
--exception
--model
--repository
--security
--service

I expected to run my application using spring boot and maven. But now that it does not work.

Upvotes: 0

Views: 1182

Answers (2)

karmakaze
karmakaze

Reputation: 36134

If you are using the normally generated project directory structure, which I believe you are, then this line:

<mainClass>src.main.java.com.linkedinSearch.api.SearchApplication</mainClass>

should be changed to:

<mainClass>com.linkedinSearch.api.SearchApplication</mainClass>

The src/main/java directory structure is not part of the package name.

Upvotes: 1

Simon Martinelli
Simon Martinelli

Reputation: 36103

First you can remove

<configuration>
    <mainClass>src.main.java.com.linkedinSearch.api.SearchApplication</mainClass>
</configuration>

This is not necessary.

But if the package name of the mainClass is wrong.

It must not include the file structure src/main/java so it would simply be:

com.linkedinSearch.api.SearchApplication

Upvotes: 1

Related Questions