SpringBoot:如何在 Spring Boot 应用程序中提供 VM 参数,同时从 Eclipse 运行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35200618/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 23:03:06  来源:igfitidea点击:

SpringBoot: How to provide VM Argument in Spring Boot App, while running from Eclipse

javaeclipsespringspring-bootjvm-arguments

提问by anij

I'm Using Spring Boot 1.3.0.RELEASE. And for my application, I'm providing some external jar path like below, while I'm running the app from CMD.

我正在使用 Spring Boot 1.3.0.RELEASE。对于我的应用程序,当我从 CMD 运行应用程序时,我提供了一些外部 jar 路径,如下所示。

java -Dloader.path="lib,config,C:/TM/ojdbc14-10.2.0.2.0.jar,spring" -jar ticketmanager-application-0.3.0-SNAPSHOT.jar

Now, when I'm trying to run the app from eclipse, I'm add the -Dloader.path="lib,config,C:/TM/ojdbc14-10.2.0.2.0.jar,spring"to VM Argument. Like the snapshot shown below.

现在,当我尝试从 Eclipse 运行应用程序时,我将添加-Dloader.path="lib,config,C:/TM/ojdbc14-10.2.0.2.0.jar,spring"到 VM 参数。如下图所示。

enter image description here

在此处输入图片说明

Editing: Adding Maven Spring Plugin configuration ------------------------

编辑:添加 Maven Spring 插件配置 ------------------------

Here, the configuration section, I have added for the loader.path

在这里,配置部分,我已经添加了 loader.path

<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>1.3.0.RELEASE</version>
                <configuration>
                    <layout>ZIP</layout>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Therefore, my question, How should I add this Argument? because it's not working :(

因此,我的问题是, 我应该如何添加此参数?因为它不起作用:(

回答by Ken Bekov

Program arguments, are arguments that passed to mainmethod of your program. Looks like space-separated list of values. Example:

程序参数,是传递给main程序方法的参数。看起来像空格分隔的值列表。例子:

java Program arg1 arg2 arg3

VM arguments, are system properties passed to the Java Virtual Machine in name=valueformat. Examle:

VM 参数,是以name=value格式传递给 Java 虚拟机的系统属性。例子:

java -Dprop1=value1 -Dprop2=value2 Program

In your case you need to add VM argumentsbut not Program arguments

在您的情况下,您需要添加VM 参数而不是程序参数

By the way, according to documentation, you can add loader.pathand loader.mainproperties right in your application.properties. Information about how to work with application.property, and how to externalize configuration settings you can find here.

顺便说,根据文件,您可以添加loader.pathloader.main就在你的属性application.propertiesapplication.property您可以在此处找到有关如何使用以及如何将配置设置外部化的信息。