【问题标题】:Spring boot maven plugin class not found找不到 Spring Boot Maven 插件类
【发布时间】:2019-01-17 08:43:43
【问题描述】:

我有三个maven项目,一个是pom包,另外两个是jar包,这里是admin-aggregator pom

<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.sounds.bvs</groupId>
    <artifactId>admin-aggregator</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>


    <modules>
        <module>../admin-lib</module>
        <module>../admin-rest</module>
    </modules>


    <properties>
        <project.build.SourceEncoding>UTF-8</project.build.SourceEncoding>
        <spring-boot-version>2.0.4.RELEASE</spring-boot-version>
        <spring-version>2.0.4.RELEASE</spring-version>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <start-class>com.sounds.bvs.AdminRestApp</start-class>
    </properties>

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

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.sounds.bvs</groupId>
                <artifactId>admin-lib</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>com.sounds.bvs</groupId>
                <artifactId>admin-rest</artifactId>
                <version>${project.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <classifier>exec</classifier>
                            <mainClass>${start-class}</mainClass>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven.compiler.plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <showDeprication>true</showDeprication>
                    <showWarnings>true</showWarnings>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

</project>

并且我没有得到 admin-rest pom.xml 及其 Main 类,因为 ctrl-click 正在导航到相应的项目,并且类型搜索能够在 admin-rest 中找到主类项目 ctrl+shift+T 也变得静止,显示相同,

<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>

    <parent>
        <groupId>com.sounds.bvs</groupId>
        <artifactId>admin-aggregator</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>admin-rest</artifactId>

    <dependencies>
        <dependency>
            <groupId>com.sounds.bvs</groupId>
            <artifactId>admin-lib</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jetty -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jetty</artifactId>
        </dependency>


    </dependencies>
</project>

主类 AdminRestApp.java,我正在尝试使用

运行管理聚合器
mvn clean spring-boot:run
mvnw.cmd clean spring-boot:run
./mvnw spring-boot:run 

但没有一个在工作

package com.sounds.bvs;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class AdminRestApp {

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



and the exception i see class not found exception i tried all which were from similar topic none helped, the start-class tag is also place and hard code the full path com.sounds.bvs.AdminRestApp in mainClass still that also did not help,

我尝试过更改 spring boot 版本以及 maven 编译器插件版本,这也很有帮助,非常需要帮助。

之前包路径很大 com.sounds.bvs.admin.rest 那个时候同样的问题改变了包名也有帮助

请让我知道我错过了什么提前谢谢。

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] `enter code here`
[INFO] admin-aggregator
[INFO] admin-lib
[INFO] admin-rest
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building admin-aggregator 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ admin-aggregator ---
[INFO] 
[INFO] >>> spring-boot-maven-plugin:2.0.4.RELEASE:run (default-cli) > test-compile @ admin-aggregator >>>
[INFO] 
[INFO] <<< spring-boot-maven-plugin:2.0.4.RELEASE:run (default-cli) < test-compile @ admin-aggregator <<<
[INFO] 
[INFO] --- spring-boot-maven-plugin:2.0.4.RELEASE:run (default-cli) @ admin-aggregator ---
[WARNING] 
java.lang.ClassNotFoundException: com.sounds.bvs.AdminRestApp
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:491)
    at java.lang.Thread.run(Thread.java:745)
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] admin-aggregator ................................... FAILURE [ 42.358 s]
[INFO] admin-lib .......................................... SKIPPED
[INFO] admin-rest ......................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 56.280 s
[INFO] Finished at: 2018-08-10T00:43:37+05:30
[INFO] Final Memory: 17M/111M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.4.RELEASE:run (default-cli) on project admin-aggregator: An exception occurred while running. com.sounds.bvs.AdminRestApp -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

【问题讨论】:

  • 我相信您的父项目的 pom.xml 文件中的两个 &lt;module&gt; 元素必须是两个子模块的名称,而不是它们的相对路径位置。
  • 这2个依赖你本地安装了吗? mvn clean install 两者都有吗?
  • 是的,两者都完成了,该 jar 在 .m2 中可用,但如果我只提供名称,我将收到以下错误 [INFO] Scanning for projects... [ERROR] [ERROR] 遇到了一些问题处理 POM 时:[错误] F:\STS Workspace\admin-aggregator\pom.xml 的子模块 F:\STS Workspace\admin-aggregator\admin-lib 不存在 @ [错误] 子模块 F:\STS F:\STS Workspace\admin-aggregator\pom.xml 的 Workspace\admin-aggregator\admin-rest 不存在 @ 然后我 google 并更改为相对路径。

标签: java maven spring-boot


【解决方案1】:

添加 spring boot 版本解决了我的问题。

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

在 Maven 选项卡中替换为您的 Spring Boot 版本 -> 插件

【讨论】:

    【解决方案2】:

    它对我有用。

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

    【讨论】:

    • 它适用于 pom 验证,但当您需要将应用程序打包到可执行 jar 中时似乎不正确(具有针对 spring boot 重新打包目标的特定配置)。在这种情况下,应该从“pluginManagement”中添加这个插件,并且必须明确设置版本。但在这种情况下,您可以使用 ${project.parent.version} 来避免对其进行硬编码。
    【解决方案3】:

    将 ${project.parent.version} 添加到 pom.xml 中的依赖项为我解决了这个问题。

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
      <version>${project.parent.version}</version>
      <type>maven-plugin</type>
    </dependency>

    【讨论】:

    • 请更具体一些,如果可能的话,请提供一个示例来说明您的建议。谢谢。
    • 我喜欢你的帖子是因为 ${project.parent.version},这样我们就可以避免对版本进行硬编码。但我会发现让它在构建/插件部分而不是依赖部分更清楚。 (我测试了它 - Spring boot 2.5.5 - 它可以工作,用于 pom 验证和打包到可执行 jar 中)
    【解决方案4】:

    我在这里阅读https://docs.spring.io/spring-android/docs/2.0.0.M3/reference/html/maven.html。 并点击链接:https://search.maven.org/ - 在搜索中输入:spring-boot-maven-plugin..

    得到我的依赖。 它对我有用。

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
      <version>2.3.4.RELEASE</version>
      <type>maven-plugin</type>
    </dependency>
    

    【讨论】:

      【解决方案5】:

      您必须从包含 Spring Boot 应用程序 (admin-rest) 的模块 maven 执行 mvn spring-boot:run 命令,而不是从父模块 (admin-aggregator)。
      但是您从父模块执行它。

      【讨论】:

      • 我也有同样的想法,但它是在电子书中给出或定义的,并要求在其上执行 mvn spring-boot:run 以便它同时启动。我是否误解了某些东西,如果我应该在 Spring Boot 应用程序(admin-rest)上运行,那么需要维护只有 pom 文件的 admin-aggregator 并且它的 maven 打包类型是 pom,如果我在 admin 上运行-休息它会运行我一开始就尝试过,仍然没有得到聚合器的用途是什么?你能建议吗
      【解决方案6】:

      我删除了.m2文件夹,重新安装了pom.xml文件,问题就解决了。

      【讨论】:

        猜你喜欢
        • 2019-01-23
        • 1970-01-01
        • 2014-06-20
        • 2014-12-22
        • 2017-03-26
        • 2015-07-22
        • 1970-01-01
        • 2018-01-29
        • 2015-08-31
        相关资源
        最近更新 更多