使用maven编译并运行Spring项目

Posted

技术标签:

【中文标题】使用maven编译并运行Spring项目【英文标题】:Compile and run Spring project with maven 【发布时间】:2018-05-03 18:28:35 【问题描述】:

我看到很多基于maven pom.xml构建文件的spring项目。还有一件奇怪的事情:项目构建时没有 public static void main() 方法。 例如:https://github.com/geowarin/spring-mvc-security。 在 spring.io 的通常示例中,有带有 @SpringBootApplication 注释的类和 SpringApplication.run(Application.class, args);在主要功能中。那么,maven如何在没有这个类的情况下构建应用程序以及如何在终端中正确地做呢?

【问题讨论】:

spring boot 应用程序和常规 spring mvc 应用程序以不同的方式工作。您指定的 git hub 链接是一个常规的 spring mvc 应用程序。它不会有任何主要方法。 main 和注解为SpringBootApplication 的应用程序是spring boot 应用程序,它们在打包、构建和启动应用程序方面完全不同 我对你想要做什么有点困惑,你只是好奇为什么 Spring MVC Security 不需要 main 方法,或者你想知道如何在你的项目? "为什么 Spring MVC Security 不需要 main 方法?"以及如何在没有这种方法的情况下运行它? (在所有自述文件中我找到了“mvn clean install”,之后什么都没有发生) 【参考方案1】:

在终端中转到项目的主目录。键入以下命令。

mvn spring-boot:run

我的项目的输出:

【讨论】:

以上是关于使用maven编译并运行Spring项目的主要内容,如果未能解决你的问题,请参考以下文章

Spring Boot(Maven)+Docker打包

由于maven插件错误,spring boot maven项目未编译

Spring Boot(Maven)+Docker打包

maven生命周期

IDEA的maven项目中 静态文件编译的问题

由 AspectJ 编译器编织的 Spring 方面在 Maven 中工作,但在 IntelliJ IDEA 中没有