Reputation: 20330
I am using spring-shell to develop a CLI app.
@SpringBootApplication
@CommandScan
public class App {
public static void main(String[] args) throws Exception {
SpringApplication application = new SpringApplication(App.class);
application.setBannerMode(Mode.OFF);
application.run(args);
}
It was working well until I ran into this problem: when I try to run my app like:
java -jar my.jar com.mycompany.App --flag
I get following exception:
Caused by: org.springframework.shell.CommandNotFound: No command found for '--flag'
at org.springframework.shell.Shell.evaluate(Shell.java:207) ~[spring-shell-core-3.1.5.jar:3.1.5]
at org.springframework.shell.Shell.run(Shell.java:159) ~[spring-shell-core-3.1.5.jar:3.1.5]
at org.springframework.shell.jline.NonInteractiveShellRunner.run(NonInteractiveShellRunner.java:146) ~[spring-shell-core-3.1.5.jar:3.1.5]
at org.springframework.shell.DefaultShellApplicationRunner.run(DefaultShellApplicationRunner.java:65) ~[spring-shell-core-3.1.5.jar:3.1.5]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:762) ~[spring-boot-3.1.5.jar:3.1.5]
It's true there is no command for --flag
. That is meant to be a startup option not a command that should be interpreted by the shell. (Problem #1).
Another problem is that spring-shell runs in NonInteractiveShellRunner
as soon as I provide some command line arguments. I want it to run in interactive mode. (Problem #2).
How can I tell it so? I read the docs but could not find solution to this puzzle.
Upvotes: 0
Views: 664
Reputation: 1
I had quite a similar issue when I tried to run an application with the spring boot CLI argument: java -jar myapp.jar --spring.config.location=myapp.properties
and got No command found for '--spring.config.location=myapp.properties'
.
So I've changed the command line to java -Dspring.config.location=myapp.properties -jar myapp.jar
.
It might be useful in your case as well.
Upvotes: 0
Reputation: 156
As far as I know, there is not option in spring-shell to tell it not to parse a command. At least not out of the box. What you can do however is parse the source String[] args
and create a new argument instance (myArgs) which does not contain the --flag
parameter and start the application with your modified args application.run(myArgs)
Upvotes: 0