简体   繁体   English

从Maven或IDE运行Spring引导项目

[英]Run Spring boot project from Maven or IDE

I've created Spring Boot based on Maven project as described in one of the official guides . 如官方指南之一所述,我已经基于Maven项目创建了Spring Boot I use IntelliJ . 我使用IntelliJ Now I can run project in one of two ways: 现在,我可以通过以下两种方式之一运行项目:

  1. Click on green arrow next to main method 单击main方法旁边的绿色箭头
  2. Type mvn spring-boot:run in the command line 在命令行中输入mvn spring-boot:run

What's the difference between these two? 两者有什么区别? Which one should I prefer and why? 我应该选择哪一个?为什么? What does IntelliJ use internally to build the project? IntelliJ内部使用什么来构建项目?

The difference is that in case 1) IntelliJ starts the JVM and runs your app and in case 2) Maven does the same. 不同之处在于,情况1)IntelliJ启动JVM并运行您的应用程序,情况2)Maven执行相同的操作。

In development I would recommend to run the Spring Boot application via IntelliJ instead of Maven. 在开发中,我建议通过IntelliJ而不是Maven运行Spring Boot应用程序。 If you run it with Maven, you bypass IntelliJ in a way so it will be less aware of what's going on and therefore less able to leverage it's assistance features. 如果使用Maven运行它,则会以某种方式绕过IntelliJ,这样它就不会知道正在发生什么,因此也就无法利用它的辅助功能。 I'm not sure if the debugger will even work, if you start the app with mvn spring-boot:run . 如果您使用mvn spring-boot:run启动应用程序,则不确定调试器是否还能mvn spring-boot:run

IntelliJ internally uses the JDK that you configured for your project to compile your Java code and if it's a Maven project it also uses Maven to assemble the classes into an app. IntelliJ在内部使用您为项目配置的JDK来编译Java代码,如果它是Maven项目,则它还使用Maven将类组装为应用程序。 That last part of your question is extremely broad if one would attempt to answer it in detail. 如果您想详细回答这个问题,那么问题的最后一部分将是极为广泛的。 But in practice, when developing a Spring Boot app, you rarely need to worry about it anyway, to be honest. 但实际上,说实话,在开发Spring Boot应用程序时,您几乎不必担心它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Maven Spring Boot插件:如何从另一个项目运行spring boot - Maven Spring Boot Plugin : how to run spring boot from another project 如何在本地 tomcat 上运行 spring 启动 maven 项目 - How to run spring boot maven project on local tomcat 如何从现有的Maven项目创建Spring Boot项目 - How to create spring boot project from existing maven project 无法在 IntelliJ IDEA 中导入 spring boot maven 项目 - IDE 导入后无响应 - Unable to import spring boot maven project in IntelliJ IDEA - IDE not responding after importing Spring 引导 maven 项目必须每次更新才能看到变化 ECLIPSE IDE - Spring boot maven project has to be updated everytime to see a change ECLIPSE IDE 在Maven项目中使用Spring Boot - using spring boot in a maven project 如何在VSCode中运行Spring Boot Maven项目以及如何配置Spring Boot Web应用程序的基本URL - How to run a Spring Boot maven project in VSCode and how to config the base url of a spring boot web application Eclipse中的Spring Boot maven项目在Intellij中不起作用 - Spring Boot maven project from Eclipse doesn't work in Intellij 如何从Spring Boot Maven Web项目调用dll调用? - How to invoke dll calls from Spring boot maven web project? 如何从Spring Boot Maven项目中删除或隐藏目标文件? - How to remove or hide target files from Spring Boot maven project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM