1

In a spring boot project who use maven. A class is not found

A part of my pom

<groupId>com.acme.pay</groupId>
<artifactId>ms.billing</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ms.billing</name>

<packaging>jar</packaging>

<properties>
    <default.package>com.acme.pay.ms.billing</default.package>
</properties>    

Structure of the project

com
  acme
    pay
      ms
        billing
          domain
          v2
          BillingServiceApplication.java

When I start application, I get this error

Error: Could not find or load main class com.acme.pay.ms.BillingServiceApplication Caused by: java.lang.ClassNotFoundException: com.acme.pay.ms.BillingServiceApplication Command execution failed.

Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.5.0:exec (default-cli) on project ms.billing: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]

It seem it don't seem in the correct path.

MWiesner
  • 8,868
  • 11
  • 36
  • 70
robert trudel
  • 5,283
  • 17
  • 72
  • 124
  • 3
    com.acme.pay.ms.BillingServiceApplication seems to be wrong. Your package has another "billing": com.acme.pay.ms.billing.BillingServiceApplication - beside that there is no need for the exec plugin. The spring-boot-maven plugin already contains a run mojo to start the application. – wemu Dec 13 '19 at 23:24
  • Your package is wrongly mentioned and compiler is looking into wrong place. Either update your class into right package or update the package name. – Rmahajan Dec 16 '19 at 13:37
  • Can you please confirm if your application is 'Spring Boot' application? If yes, then while running your application as 'Java application', just choose the main file as 'BillingServiceApplication'. There is no problem with your pom file. If no, then could you please share your pom file with all dependencies? I think that you need to change the version of the dependency 'org.codehaus.mojo:exec-maven-plugin'. – Anurag Dec 18 '19 at 02:57
  • 2
    Please share code of `BillingServiceApplication` – Smile Dec 18 '19 at 08:27
  • May be issue coming at building the project due to your package and main class configuration is not perfect. -Make package name like this "com.acme.pay.ms.billing.BillingServiceApplication" – Sonu patel Dec 23 '19 at 06:48

4 Answers4

0

Your problem might be related to your artifactId having a . character in it. I've never seen an artifactId formatted like that and I think it might be messing up the path resolution. Usually people use - as a separator when they want to make an artifactId more readable (as per commons-math in the maven guide linked below).

http://maven.apache.org/guides/mini/guide-naming-conventions.html

choose whatever name you want with lowercase letters and no strange symbols

Shorn
  • 19,077
  • 15
  • 90
  • 168
0

Can you please confirm if your application is 'Spring Boot' application?

If yes, then while running your application as 'Java application', just choose the main file as 'BillingServiceApplication'. There is no problem with your pom file.

If no, then could you please share your pom file with all dependencies?

I think that you need to change the version of the following dependency

'org.codehaus.mojo:exec-maven-plugin'.

Just check the link for similar question on stackoverflow:

Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2:java (default-cli)

I hope this helps!

Anurag
  • 843
  • 1
  • 9
  • 16
0

did you annotate your class with @Component, @Services etc OR if your class out of the scan scoop you could included it via

@ComponentScan(basePackages = "com.acme.pay.ms.billing")
@Configuration
public class SpringComponentScanApp {

Or you could use xml as in your case via

<context:component-scan base-package="com.acme.pay.ms.billing" />
Noa
  • 315
  • 1
  • 7
  • 31
0

Package of BillingServiceApplication should be com.acme.pay.ms.billing.BillingServiceApplication

Smile
  • 3,832
  • 3
  • 25
  • 39