0

I am trying to create a CLI application that has several commands using Spring Shell, having dependencies on another project and Spring. This is my pom:

  <groupId>es.uca.dss.sigeca</groupId>
  <artifactId>cli</artifactId>
  <version>1.0</version>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>es.uca.dss.sigeca</groupId>
      <artifactId>core</artifactId>
      <version>0.1</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
        <version>3.0.6</version>
    </dependency>
    <dependency>
    <groupId>org.springframework.shell</groupId>
    <artifactId>spring-shell-starter</artifactId>
    <version>2.1.5</version>
    </dependency>
  </dependencies>

  <build>
      <plugins>
        <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.1.2</version>
          <configuration>
            <archive>
              <manifest>
                <mainClass>es.uca.dss.sigeca.Main</mainClass>
              </manifest>
            </archive>
          </configuration>
        </plugin>
        <!--  Add the assemble plugin with standard configuration  -->
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>3.3.0</version>
          <configuration>
            <archive>
              <manifest>
                <mainClass>es.uca.dss.sigeca.Main</mainClass>
              </manifest>
            </archive>
            <descriptorRefs>
              <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
          </configuration>
          <executions>
            <execution>
              <id>make-assembly</id>
              <phase>package</phase>
              <goals>
                <goal>single</goal>
              </goals>
            </execution>
          </executions>
        </plugin>  
      </plugins>
  </build>
</project>

The Main.java is the following:

package es.uca.dss.sigeca;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

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

And my commands:

package es.uca.dss.sigeca;

import org.springframework.shell.standard.ShellMethod;

import java.util.Date;

import org.springframework.shell.standard.ShellComponent;

@ShellComponent
public class MyCommands 
{
    IServicesClient servicesClient = ServicesProvider.getClientServices();
    IServicesVehicle servicesVehicle = ServicesProvider.getVehicleServices();
    IServicesReserve servicesReserve = ServicesProvider.getReserveServices();
    
    @ShellMethod("Consults if a car is avalaible between two determined dates.")
    public void consultDisponibility(String enrollment, Date start, Date end)
    {
        if(servicesReserve.isAvailable(servicesVehicle.getVehicle(enrollment), start, end))
        {
            System.out.println("It is avalaible.\n");
        } else System.out.println("It is not avalaible.\n");
    }
    
    @ShellMethod("Register a new client.")
    public void clientRegister(String ID, String contact, String name)
    {
        servicesClient.registerClient(ID, contact, name);
    }
    
    @ShellMethod("Edit data from a client.")
    public void clientEdit(String ID, String contact, int incidences)
    {
        servicesClient.editClient(ID, contact, incidences);
    }
}

Dependencies with the other project seems to be fine, as the .jar generated file contains them, and i have no compiling problems.

I tried to execute it with mvn clean install -DskipTests and then java -jar target/cli1.0-jar-with-dependencies.jar, and spring initialices, but there is no Spring Shell output or prompt for me to issue the commands, it just finishes executing.

This is the output:

java -jar target/cli-1.0-jar-with-dependencies.jar 

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.0.6)

15:31:09.186 [main] INFO es.uca.dss.sigeca.Main -- Starting Main using Java 17.0.7 with PID 39497 (/home/alex/Documentos/DSS/dss2022-2023-SiGeCa/cli/target/cli-1.0-jar-with-dependencies.jar started by alex in /home/alex/Documentos/DSS/dss2022-2023-SiGeCa/cli)
15:31:09.190 [main] DEBUG es.uca.dss.sigeca.Main -- Running with Spring Boot, Spring
15:31:09.192 [main] INFO es.uca.dss.sigeca.Main -- No active profile set, falling back to 1 default profile: "default"
15:31:09.194 [main] DEBUG org.springframework.boot.SpringApplication -- Loading source class es.uca.dss.sigeca.Main
15:31:09.309 [main] DEBUG 

/* A lot of mor DEBUGs... */

'org.springframework.boot.autoconfigure.sql.init.SqlInitializationAutoConfiguration'
15:31:11.105 [main] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory -- Creating shared instance of singleton bean 'spring.sql.init-org.springframework.boot.autoconfigure.sql.init.SqlInitializationProperties'
15:31:11.143 [main] INFO es.uca.dss.sigeca.Main -- Started Main in 2.279 seconds (process running for 2.6)
15:31:11.146 [SpringApplicationShutdownHook] DEBUG org.springframework.context.annotation.AnnotationConfigApplicationContext -- Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@2b4a2ec7, started on Tue Apr 25 15:31:09 CEST 2023

I hope anyone can help me, I've been around this for a long time now.

0 Answers0