spring-projects / spring-shell

Spring based shell
http://projects.spring.io/spring-shell/
Apache License 2.0
710 stars 391 forks source link

Shell Prompt not working and jline Unable to create a system terminal #1096

Closed SubhamDeveloperGupta closed 2 days ago

SubhamDeveloperGupta commented 1 week ago

Hi everyone, recently I started spring-shell and I have added a basic command when I try to run the application shell prompt that is not coming.

I have tried to find a solution and all the solutions are still not coming.

could you help me with this?

Pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.3.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>shell-example</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>shell-example</name>
    <description>Demo project for Spring Boot</description>
    <url/>
    <licenses>
        <license/>
    </licenses>
    <developers>
        <developer/>
    </developers>
    <scm>
        <connection/>
        <developerConnection/>
        <tag/>
        <url/>
    </scm>
    <properties>
        <java.version>17</java.version>
        <spring-shell.version>3.3.0</spring-shell.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.shell</groupId>
            <artifactId>spring-shell-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.projectreactor</groupId>
            <artifactId>reactor-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.shell</groupId>
            <artifactId>spring-shell-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.shell</groupId>
                <artifactId>spring-shell-dependencies</artifactId>
                <version>${spring-shell.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.graalvm.buildtools</groupId>
                <artifactId>native-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

main class

package com.example.shell_example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.shell.standard.ShellComponent;
import org.springframework.shell.standard.ShellMethod;

@SpringBootApplication
@ShellComponent
public class ShellExampleApplication {

    @ShellMethod(key = "hello", value = "I will say Hello")
    public String hello() {
        return "Hello World!";
    }

    public static void main(String[] args) {
        SpringApplication.run(ShellExampleApplication.class, args);
    }

}

Output


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.3.1)

2024-06-26T18:09:32.838+05:30  INFO 27988 --- [shell-example] [           main] c.e.s.ShellExampleApplication            : Starting ShellExampleApplication using Java 17.0.10 with PID 27988 (C:\Users\Subham Kr Gupta\Documents\spring\shell-example\target\classes started by Subham Kr Gupta in C:\Users\Subham Kr Gupta\Documents\spring\shell-example)
2024-06-26T18:09:32.842+05:30  INFO 27988 --- [shell-example] [           main] c.e.s.ShellExampleApplication            : No active profile set, falling back to 1 default profile: "default"
2024-06-26T18:09:35.959+05:30  WARN 27988 --- [shell-example] [           main] org.jline                                : Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)
2024-06-26T18:09:36.693+05:30  INFO 27988 --- [shell-example] [           main] o.s.b.web.embedded.netty.NettyWebServer  : Netty started on port 8080 (http)
2024-06-26T18:09:36.715+05:30  INFO 27988 --- [shell-example] [           main] c.e.s.ShellExampleApplication            : Started ShellExampleApplication in 4.601 seconds (process running for 5.245)
rabestro commented 1 week ago

@SubhamDeveloperGupta the same issue. I roll back to version 3.2.6 - which works fine. I suppose this is an error in version 3.3.1

rabestro commented 1 week ago

@SubhamDeveloperGupta let's try add this properties:

spring.shell.interactive.enabled=true
spring.shell.script.enabled=true
jvalkeal commented 2 days ago

Indeed interactive runner needs to be activated. Mentioned in docs and wiki https://github.com/spring-projects/spring-shell/wiki/Spring-Shell-3.3-Release-Notes.

You'll get dump terminal on windows if you don't have either jna or jansi. You can i.e. use spring-shell-starter-jna.

SubhamDeveloperGupta commented 2 days ago

Hi @rabestro Yes I have tried and it's working fine now. Thank You

Solution spring.shell.interactive.enabled=true spring.shell.script.enabled=true

SubhamDeveloperGupta commented 2 days ago

Solution spring.shell.interactive.enabled=true spring.shell.script.enabled=true

Thank You @rabestro @jvalkeal