为spring boot应用程序生成war包时maven构建失败?
这是我在SO上一个问题的延伸。根据这篇文章,生成为spring boot应用程序生成war包时maven构建失败?,spring,maven,tomcat,spring-boot,Spring,Maven,Tomcat,Spring Boot,这是我在SO上一个问题的延伸。根据这篇文章,生成可部署战争 我正在尝试为这个简单的应用程序生成一个可部署的war。源代码可以为这个示例应用程序找到 按照spring boot for jar到war转换的说明,我更改了我的pom.xml,以反映以下内容。(刚刚添加了具有范围的tomcat依赖项) 参考: 我试过两种情况。两者都失败,出现以下错误(无法找到主类) 无主方法(注:我已注释掉上面的主方法) 没有application.Java文件(注释掉了该文件中的所有内容-此处未显示) 错误: [I
可部署战争
我正在尝试为这个简单的应用程序生成一个可部署的war
。源代码可以为这个示例应用程序找到
按照spring boot for jar到war转换的说明,我更改了我的pom.xml
,以反映以下内容。(刚刚添加了具有范围的tomcat
依赖项
)
参考:
我试过两种情况。两者都失败,出现以下错误(无法找到主类
)
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.218s
[INFO] Finished at: Thu Apr 23 11:46:24 PDT 2015
[INFO] Final Memory: 22M/222M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.2.3.RELEASE:repackage (default) on project gs-uploading-files: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.2.3.RELEASE:repackage failed: Unable to find main class -> [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/PluginExecutionException
PS:当我的main方法完好无损时,构建是成功的如果您想同时获得这两个好处,即嵌入Tomcat的独立可执行war和可在外部Tomcat中部署的正常war,您需要有一个带有main方法的类。所以
- 在Application.java中启用main()方法李>
- 配置
以指定带有主类的类(如果有主类,spring应该会找到它,但我想最好是显式的):springbootmaven-plugin
org.springframework.boot springbootmaven插件 ${spring启动版本} 应用程序包 重新包装
- 使用提供的
范围删除pom中的
依赖项。Spring boot神奇地知道如何启用/禁用嵌入式Tomcatspring boot starter tomcat
我目前正在使用Spring Boot 1.0.1.RELEASE构建REST API,并使用这种设置,它在所有三种模式下都非常有效。请注意,您可以从以下几方面获得类似的信息:
未能执行目标org.springframework.boot:spring boot maven plugin:1.3.2.发布:在项目Xyz上重新打包(默认):执行目标org.springframework.boot:spring boot maven plugin:1.3.2.发布:重新打包失败:无法从以下候选对象中找到单个主类[com.a.Application、com.a.fake.Application、com.a.main.Main1、com.a.runner.DataImportRunner、com.a.temp.dependencyinjection.MainApp、com.a.finalapp.facade.impl.V3DataImports、com.a.finalapp.service.impl.App2]
(我在尝试运行Maven安装时在应用程序中看到) 在我的例子中,我有多种主要方法,Spring无法自动选择我想要的方法
解决方案与Naymesh Mistry之前概述的相同(在pom.xml中显式指定您的.main.class.with.package.prefix)您是否还有机会在pom.xml中引用您的主类?@ci\ux:我不确定您的确切意思。我已经用我的整个pom.xml更新了。除了您链接问题的答案之外,我找不到任何证据表明您可以省略主类,即带有main方法的类。spring boot maven插件似乎正在寻找如果你没有使用这个插件,但不确定是否值得。如果你只想作为标准war文件运行这个应用程序,你可以完全删除启动插件,或者重新配置它,这样重新打包的目标就不会绑定到Maven的生命周期。对于本地测试,我更喜欢嵌入式Tomcat。但是对于部署,我需要我不知道,即使不配置SpringBootMaven插件(如您所建议的),我如何才能同时获得这两个好处,如果我有main方法,它可以与嵌入式和部署战一起工作。如果我只想启用部署战模式,似乎我还需要使用
main
。否则我无法让它工作。没错,如果你不指定主类,插件将搜索带有公共静态void main(String[]args)的类方法。为了可读性,我个人更喜欢显式指定类。但是,是的,它不需要显式指定。如果您只想在正常war模式下启用部署,您根本不需要在pom中使用spring boot maven plugin
。谢谢,在生产中,我怀疑是否有人使用嵌入式Tomcat服务器。因此,我更愿意部署war
。如果要删除spring boot maven插件
,我是不是只删除了主要方法
搜索,还是丢失了一些重要的东西?没错。嵌入式Tomcat更易于分发(例如,您的测试人员不需要先安装任何Tomcat)在开发和测试过程中进行部署。在生产过程中,应使用常规war。删除spring boot maven插件
,主要方法只应删除war中的独立可执行/嵌入式Tomcat功能,其他什么都不做(仅在我的应用程序上测试了此功能,效果良好:))如果您有选择,建议使用部署可执行war或jar的方法。
@SpringBootApplication
public class Application extends SpringBootServletInitializer{
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
/*public static void main(String[] args) {
SpringApplication.run(Application.class, args);
} */
}
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.218s
[INFO] Finished at: Thu Apr 23 11:46:24 PDT 2015
[INFO] Final Memory: 22M/222M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.2.3.RELEASE:repackage (default) on project gs-uploading-files: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:1.2.3.RELEASE:repackage failed: Unable to find main class -> [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/PluginExecutionException