Reputation: 523
I use maven plugin to set the main class like this :
<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
Upvotes: 23
Views: 27495
Reputation: 671
Following command will do the trick:
java -cp my-app.jar -Dloader.main=myApplicationClass org.springframework.boot.loader.launch.PropertiesLauncher
Upvotes: 52
Reputation: 3467
For WAR files:
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
Upvotes: 1
Reputation: 58124
There's a launcher for that in Spring Boot already. You need to build the jar with that as the Main-Class (by setting the layout
in the build config).
Upvotes: 7
Reputation: 229
Executing from Windows PowerShell I needed this format (with the quotes):
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.
Upvotes: 4