简体   繁体   English

指定主类 Spring-Boot 命令行

[英]Specify main class Spring-Boot command line

I use maven plugin to set the main class like this :我使用 maven 插件来设置主类,如下所示:

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
    <mainClass>com.myapp.main.MainClass</mainClass>
</configuration>
</plugin>

But sometimes I want run my app with another main class.但有时我想用另一个主类运行我的应用程序。 What is the command line arguments to do this?执行此操作的命令行参数是什么?

java -jar myapp-1.0.jar ...

Thx谢谢

以下命令可以解决问题:

java -cp my-app.jar -Dloader.main=myApplicationClass org.springframework.boot.loader.PropertiesLauncher

There's a launcher for that in Spring Boot already . Spring Boot 中已经有一个启动器 You need to build the jar with that as the Main-Class ( by setting the layout in the build config ).您需要将 jar 构建为 Main-Class ( 通过在构建配置中设置layout )。

Executing from Windows PowerShell I needed this format (with the quotes):从 Windows PowerShell 执行我需要这种格式(带引号):

java -cp .\\myjarfile.jar -D"loader.main=com.app.etc.FullyQualifiedMainClass" org.springframework.boot.loader.PropertiesLauncher

To clarify the accepted answer: You can directly modify the loader.main property in the jar's META-INF/MANIFEST.MF file, if you're ok with a more static solution.澄清接受的答案:如果您对更静态的解决方案没有意见,您可以直接修改 jar 的 META-INF/MANIFEST.MF 文件中的 loader.main 属性。

对于 WAR 文件:

java -cp salamander-1.0.0.war -Dloader.path=WEB-INF/classes,WEB-INF/lib -Dloader.main=com.frog.katak.MyMainClass org.springframework.boot.loader.PropertiesLauncher

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM