[英]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: 现在,我可以通过以下两种方式之一运行项目:
main
method main
方法旁边的绿色箭头 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.