Spring Boot:重命名Main类

[英]Spring Boot: Renaming the Main class


I'm new to Spring and Spring Boot, but I'm using it as a template.

我是Spring和Spring Boot的新手,但我正在使用它作为模板。

The Main.java file contains in part the following:

Main.java文件部分包含以下内容:

package com.example;

@Controller
@SpringBootApplication
public class Main {

}

Unfortunately I need to import another class that is called Main, and use it in this class. The other class is in a Jar and I don't really want to recompile it, so I was thinking the best way would be to rename this Main.

不幸的是,我需要导入另一个名为Main的类,并在此类中使用它。另一个类在Jar中,我真的不想重新编译它,所以我认为最好的方法是重命名这个Main。

However when I do that (renaming it to JavaGettingStarted), the Maven plugin for Spring Boot will fail:

但是,当我这样做(将其重命名为JavaGettingStarted)时,Spring Boot的Maven插件将失败:

[ERROR] Failed to execute goal
org.springframework.boot:spring-boot-maven-plugin:2.0.0.RELEASE:repackage
(default) on project java-getting-started: Execution default of goal
org.springframework.boot:spring-boot-maven-plugin:2.0.0.RELEASE:repackage
failed: Unable to find a single main class from the following
candidates [com.example.JavaGettingStarted, com.example.Main] -> [Help
1]

Is Main some sort of default? Can I change it?

Main是某种默认值吗?我可以改变吗?

1 个解决方案

#1


3  

The problem is not the name of the class, but rather that the Spring Boot Maven plugin detected two classes with a main method. Either delete one of those main methods, or explicitly configure the maven plugin:

问题不是类的名称,而是Spring Boot Maven插件使用main方法检测到两个类。要么删除其中一个主要方法,要么显式配置maven插件:

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <version>2.0.0.RELEASE</version>
  <configuration>
    <mainClass>Your class name here</mainClass>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>repackage</goal>
      </goals>
    </execution>
  </executions>
</plugin>
智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2018/03/16/7205e6c32ee021464f97eb24432559f5.html



猜您在找
重命名类会导致IBOutlet连接失败 - Renaming class causes IBOutlet connection to fail 除了重构和重命名类或属性名之外,swift还有什么选项? - What is other option available in swift instead of refactoring and renaming class or attribute name? Spring Boot Program无法找到主类 - Spring Boot Program cannot find main class 暴露给Objective-C代码时Swift类的名称不尊重@objc重命名 - Name of Swift class when exposed to Objective-C code does not respect the @objc renaming 使用south重命名django模型类名和相应的外键,而不会丢失数据 - Renaming a django model class-name and corresponding foreign keys with south, without loosing the data
智能推荐
 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告