programing

Eclipse의 스프링 부트 프로젝트에서 Maven과 함께 "메인 클래스를 찾을 수 없음"

elseif 2023. 4. 4. 21:06

Eclipse의 스프링 부트 프로젝트에서 Maven과 함께 "메인 클래스를 찾을 수 없음"

나는 메이븐 프로젝트를 더 이상 컴파일할 수 없기 때문에 매우 절망적이다.지금까지 7개의 maven 모듈로 분할된 논리프로젝트가 1개 있었는데 오늘은 기능을 도입하여 실수로 원형 maven 의존관계를 생성했습니다.그래서 코드를 리팩터링하여 순환 의존성을 없앴습니다.폼파일을 업데이트해서 수정사항을 반영했더니 내 프로젝트가 더 이상 구축되지 않더군요."-X 클린 설치"에서 maven을 실행하면 다음과 같은 java.lang이 나타납니다.InlawalStateException:주 클래스를 찾을 수 없습니다.

[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] agiletunes-parent
[INFO] agiletunes-util
[INFO] agiletunes-security-common
[INFO] agiletunes-marketing-persistence
[INFO] agiletunes-common-ui
[INFO] agiletunes-security-client
[INFO] agiletunes-marketing-application
[INFO] agiletunes-security-server
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building agiletunes-parent 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- spring-boot-maven-plugin:1.5.2.RELEASE:repackage (default) @ agiletunes-parent ---
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ agiletunes-parent ---
[INFO] Installing C:\Users\Alexander\Documents\Development\agileTunes\agiletunes-parent\pom.xml to C:\Users\Alexander\Documents\Development\mavenArtifacts\com\agiletunes\agiletunes-parent\0.0.1\agiletunes-parent-0.0.1.pom
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building agiletunes-util 0.0.1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ agiletunes-util ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\Alexander\Documents\Development\agileTunes\agiletunes-util\src\main\resources
[INFO] skip non existing resourceDirectory C:\Users\Alexander\Documents\Development\agileTunes\agiletunes-util\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ agiletunes-util ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ agiletunes-util ---
[INFO] Not copying test resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ agiletunes-util ---
[INFO] Not compiling test sources
[INFO] 
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ agiletunes-util ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- maven-jar-plugin:2.6:jar (default-jar) @ agiletunes-util ---
[INFO] 
[INFO] --- spring-boot-maven-plugin:1.5.2.RELEASE:repackage (default) @ agiletunes-util ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] agiletunes-parent .................................. SUCCESS [  1.492 s]
[INFO] agiletunes-util .................................... FAILURE [  1.095 s]
[INFO] agiletunes-security-common ......................... SKIPPED
[INFO] agiletunes-marketing-persistence ................... SKIPPED
[INFO] agiletunes-common-ui ............................... SKIPPED
[INFO] agiletunes-security-client ......................... SKIPPED
[INFO] agiletunes-marketing-application ................... SKIPPED
[INFO] agiletunes-security-server ......................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.674 s
[INFO] Finished at: 2017-03-21T21:53:04+01:00
[INFO] Final Memory: 31M/309M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.2.RELEASE:repackage (default) on project agiletunes-util: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.5.2.RELEASE:repackage failed: Unable to find main class -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.2.RELEASE:repackage (default) on project agiletunes-util: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.5.2.RELEASE:repackage failed: Unable to find main class
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.5.2.RELEASE:repackage failed: Unable to find main class
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
    ... 20 more
Caused by: java.lang.IllegalStateException: Unable to find main class
    at org.springframework.boot.loader.tools.Repackager.buildManifest(Repackager.java:354)
    at org.springframework.boot.loader.tools.Repackager.repackage(Repackager.java:273)
    at org.springframework.boot.loader.tools.Repackager.repackage(Repackager.java:258)
    at org.springframework.boot.loader.tools.Repackager.repackage(Repackager.java:190)
    at org.springframework.boot.maven.RepackageMojo.repackage(RepackageMojo.java:212)
    at org.springframework.boot.maven.RepackageMojo.execute(RepackageMojo.java:199)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    ... 21 more
[ERROR] 
...

이것은 maven parent 프로젝트의 pom.xml 입니다.

<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.agiletunes</groupId>
<artifactId>agiletunes-parent</artifactId>
<version>0.0.1</version>

<packaging>pom</packaging>
<name>agiletunes-parent</name>
<description>Maven parent project of agiletunes</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.2.RELEASE</version>
    <relativePath></relativePath>
</parent>

<modules>
    <module>../agiletunes-common-ui</module>
    <module>../agiletunes-marketing-application</module>
    <module>../agiletunes-marketing-persistence</module>
    <module>../agiletunes-security-client</module>
    <module>../agiletunes-security-common</module>
    <module>../agiletunes-security-server</module>
    <module>../agiletunes-util</module>
</modules>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <!-- Java -->
    <java.version>1.8</java.version>

    <!-- Spring -->
    <spring.boot.version>1.5.2.RELEASE</spring.boot.version>

    <!-- persistence -->
    <mysql-connector-java.version>6.0.5</mysql-connector-java.version>

    <!-- util -->
    <guava.version>17.0</guava.version>

    <!-- testing -->
    <mockito.version>1.9.5</mockito.version>

</properties>

<dependencies>

    <!-- Spring -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>${mysql-connector-java.version}</version><!--$NO-MVN-MAN-VER$ -->
        <scope>runtime</scope>
    </dependency>

    <!-- utils -->
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>${guava.version}</version>
    </dependency>

    <!-- unit test framework -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <version>${mockito.version}</version>
        <scope>test</scope>
    </dependency>

</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

이걸 고치려면 어떻게 해야 하죠?추가 정보가 필요하시면 알려주세요.잘 부탁드립니다.

이거 먹어야지

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

실행하려는 모듈만 해당되며 부모 폼에서는 사용할 수 없습니다.

비슷한 문제에 직면한 사람에게만요.나는 덧붙였다.spring-boot-maven-plugin섹션의 부모 POM에서pluginManagement다음과 같은 섹션입니다.

 <build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

다음으로 플러그인을 사용하는 모듈에만 추가했습니다.plugin를 참조해 주세요.그 후 프로젝트는 성공적으로 구축되었습니다.

폼의 속성 섹션에서 이것을 추가해 보세요.

<start-class>your.package.main</start-class>

spring-boot 프로젝트의 메인 클래스가 없는 경우 spring-boot-mapen-slash를 다음과 같이 실행할 수 있습니다.

 <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
</build>

저도 같은 문제가 있었어요.실제로 실행되지 않는(메인 클래스 없음) 서브프로젝트에서의 spring boot mvn 플러그인 선언으로 종료되었습니다.spring boot mvn 플러그인을 서브모듈에서 제거했는데 모두 정상적으로 실행되었습니다.

프로젝트에서 agiletunes-util pom.xml 추가

<properties>
   <spring-boot.repackage.skip>true</spring-boot.repackage.skip>
</properties>

이와 같은 maven 속성에 속성을 추가합니다.

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <start-class>org.roshan.Application</start-class>
</properties>

저도 비슷한 문제가 있었어요.pom.xml데이터 모델을 새 모듈로 분리하기 위해 작성되었습니다.

이 트레드를 읽다 보니 실수로 그 발판을 놓았더군요.<configuration><skip>true</skip></configuration>내부<executions>블록. 아래는 수정한 내용입니다. pom.xml[ Build 。참고로, 없습니다. <packaging>내 엔트리pom.xml.

Ubuntu 20.04 LTS, Java 11.0.7, maven 3.6.3, Spring Starter 2.3.2 사용.릴리즈, IntelliJ 2020.2

데이터 모델 모듈의 pom.xml 빌드 구성 작업 중

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>

난 그걸 해결했어.

다음 코드를 pom 파일에 추가합니다.

<profiles>
    <profile>
        <id>profile1</id>
        <properties>
            <spring.boot.mainclass>com.detaysoft.Application</spring.boot.mainclass>
        </properties>
    </profile>
</profiles>

그런 다음 다음과 같이 빌드 태그를 작성합니다.

    <build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                    <configuration>
                        <mainClass>${spring.boot.mainclass}</mainClass>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

되지 @SpringBootApplication

https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-using-springbootapplication-annotation.html

Boot 에 "Spring Boot"에 .@Configuration,@EnableAutoConfiguration ★★★★★★★★★★★★★★★★★」@ComponentScan 주석들은 되기 때문에( 위의 베스트프랙티스를 ), 한 Spring Boot을 @SpringBootApplication★★★★★★ 。

I was also facing the same issue is resolved by adding 저도 같은 문제에 직면해 있었습니다.<id>repackage</id>.

 <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>repackage</id>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>

여러 모듈 맵프로젝트가 있는 경우 첫 번째 회피책으로 재패키지를 디세블로 하면 이 예외를 피할 수 있습니다.

<properties>
    <spring-boot.repackage.skip>true</spring-boot.repackage.skip>
</properties>

기타 워크라우드:

<executions>
      <execution>
          <goals>
               <goal>repackage</goal>
           </goals>
      </execution>
</executions>
<configuration>
      <skip>true</skip>
</configuration>

해결책:

  <properties>
        <spring.boot.mainclass>ir.shaparak.Application</spring.boot.mainclass>
     </properties>

또 다른 솔루션:부모 POM 에서는, 다음의 조작을 실시합니다.

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

하위 모듈(실행 가능 무들)은 다음과 같아야 합니다.

   <build>
          <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
           </plugins>
    </build>

이 문제에 대해 우연히 발견했고 포장 유형이 잘못되었어요.저도 우연히 이 문제를 발견했는데, 포장 타입이 잘못되었다는 것을 알게 되었습니다. When I changed 내가 변했을 때packaging부에서pom to 로.jar, , everything started to work correctly., 모든 것이 올바르게 동작하기 시작했습니다.

제 경우 "source Directory"를 추가해야 했고 pom.xml이 다음에서 변경되었습니다.

...

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

...

로.

...

<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

...

In my case, I had a code source file named 제 경우엔 코드 소스 파일이 있었는데java내가 분명히 사용했는데도kotlin:

<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>

Maven을 사용하면 다음과 같이 메인 클래스를 구분할 수 있습니다.

<build>
  <plugins>
    <plugin>
      <configuration>
        <mainClass>com.xxx.yyy.mainApplication<mainClass>
      <configuration>
    <plugin>
  <plugins>
</build>

내 경우, 나는 progect pom의 bellow tag를 놓쳤다.

<packaging>jar</packaging>

또는

<packaging>war</packaging>

그래서 추가했는데 잘 되더라고요.

멀티 모듈 프로젝트에서도 같은 문제가 있었고, 추가했습니다.<mainClass>package-name-in-which-main-method-resides</mainClass>그리고 그것은 성공하였다.

<build>
<plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
    <mainClass>package-name-where-@SpringBootApplication-main-method-is(com.agiletunes)</mainClass>
    </configuration>
    </plugin>
</plugins>
</build>

제 경우 kotlin 프로젝트가 있었는데 IDE에 의해 src dir가 kotlin이 아닌 java로 명명되었습니다.이름을 수정하면 문제가 해결되었습니다.

아래

<artifactId></artifactId>

태그 이 속성 쓰기

<properties>
<spring-boot.repackage.skip>true</spring-boot.repackage.skip>
</properties>

그것은 나에게 도움이 된다

<properties>
        <spring-boot.repackage.skip>true</spring-boot.repackage.skip>
</properties>

이것은 당신의 pom.xml에서 동작합니다.이것에 의해서, 프로그램이 메인 클래스를 검색해, 모든 의존 관계를 1개의 fat jar에 재패키지 할 수 있습니다.단, 모듈에 메인 클래스가 포함되어 있지 않은 경우는, 모듈의 pom 파일에 상기의 코드로 지정할 필요가 있습니다.

maven을 사용하여 Sprint Boot 프로젝트를 수동으로 빌드하는 경우 프로젝트에 "class Application extends Spring Boot Servlet"과 같은 클래스가 있는지 확인하십시오.Initializer " (메인 메서드 포함)

저도 같은 문제가 있어서 어플리케이션클래스를 추가하여 해결했습니다.

@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

프로젝트 구성 중에 애플리케이션 시작점을 추가하지 못했습니다.

이 문제를 해결하려면 다음 두 가지 방법이 있습니다.

  1. 기본 클래스 만들기:
public class Main {public static void main(String[] args){}}
  1. pom.xml에서 플러그인 제거:
<plugin>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

언급URL : https://stackoverflow.com/questions/42937577/unable-to-find-main-class-with-maven-on-spring-boot-project-in-eclipse