0

I want to use the command "mvn spring-boot:run" but I want to use it with some arguments or something that allows me to use only DemoApplication.java and runs the project without any errors. Warnings are NOT a problem.

I cannot delete the other @SpringBootApplication Annotated file named SecureAppApplication nor change its content. (Courtesy of a strict Professor with unreasonable demands)

Here is the relevant error message after executing command: mvn spring-boot:run

[ERROR] Failed to execute goal org.springframework.boot:spring-boot- 
maven-plugin:2.1.8.RELEASE:run (default-cli) on project myproject: 
Execution default-cli of goal org.springframework.boot:spring-boot- 
maven-plugin:2.1.8.RELEASE:run failed: Unable to find a single main 
class from the following candidates  
[com.example1.example1.DemoApplication, 
com.example1.example1.secureapp.SecureAppApplication] 

Here is the DemoApplication file code:

package com.example1.example1;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
    SpringApplication.run(DemoApplication.class, args);
    System.out.println("System is working!");
}
}

Here is the SecureAppApplication.java file code:

package com.example1.example1.secureapp;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
@SpringBootApplication
public class SecureAppApplication {
public static void main(String[] args) {
    SpringApplication.run(SecureAppApplication.class, args);
}
}
Semper_fi
  • 25
  • 6
  • have you tried specifiing what main your application needs to use?(MANIFEST file) The error that is thrown doesn't really look from spring but form the jvm itself – Joris D R. Oct 15 '19 at 08:12
  • Please try to find the answer before asking. Thanks https://stackoverflow.com/a/37264008/2865414 – Tea Oct 15 '19 at 08:15
  • I'm curious why you need 2 main class files. I think we can use profiles instead of creating 2 main classes. Check out this tutorial to see https://www.baeldung.com/spring-yaml – Tea Oct 15 '19 at 08:18
  • @TeaNG thanks.I don't need 2 main classes, I just forgot to delete one of them and submitted my project. – Semper_fi Oct 15 '19 at 08:24
  • I got your point. Should be careful next time :D – Tea Oct 15 '19 at 08:24
  • Possible duplicate of [Running multiple SpringBootApplication classes from a single maven project](https://stackoverflow.com/questions/37245820/running-multiple-springbootapplication-classes-from-a-single-maven-project) – Semper_fi Oct 15 '19 at 08:26
  • Flagged it as duplicate. – Semper_fi Oct 15 '19 at 08:26

1 Answers1

0

From the command line, you can specify the main class that you want to execute

mvn spring-boot:run -Dstart-class=com.your.package.application.BookApplication

Devratna
  • 938
  • 1
  • 7
  • 26