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是某種默認值嗎?我可以改變嗎?
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>
本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2018/03/16/7205e6c32ee021464f97eb24432559f5.html。