0

Windoze 7 Java 1.8 Spring Boot 2.0.2.RELEASE Eclipse Oxygen

I've crafted a basic Spring Boot app. Maven creates an executable jar successfully. Turning on TaskManager->Processes then executing the jar within a PowerShell with

java -jar Foo.jar

I do see a a java.exe appear in the TaskManager and do see a few lines written to the console. So far so good. But then java.exe ends after about 5sec and disappears from the TaskManager->Processes and the console returns to a prompt.

Now I would think the executable would run until terminated with Ctrl-C .

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 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>SpringBootExample</groupId>
  <artifactId>SpringBootExample</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.2.RELEASE</version>
    <relativePath/>
  </parent>
  
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <jdk.version>1.8</jdk.version>
    <spring.version>4.3.17.RELEASE</spring.version>
    <junit.version>4.12</junit.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  </properties> 

  <dependencies>

    <!-- needed to make Jackson serialize new Java 8 date/time stuff correctly -->
    <dependency> 
      <groupId>com.fasterxml.jackson.datatype</groupId>
      <artifactId>jackson-datatype-jsr310</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-json</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-logging</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <exclusions>
        <exclusion>
          <groupId>org.junit-vintage</groupId>
          <artifactId>junit-vintage-engine</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>
  
  <build>
    <finalName>SpringBootExample</finalName>
    <directory>target</directory>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
      </resource>
      <resource>
        <directory>src/main/java</directory>
      </resource>
    </resources>
    <sourceDirectory>src/main/java</sourceDirectory>
    <testSourceDirectory>src/test/java</testSourceDirectory>
    <plugins>
          
    <!-- Set JDK Compiler Level -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.7.0</version>
        <configuration>
          <source>${jdk.version}</source>
          <target>${jdk.version}</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
          <configuration>
            <executable>true</executable>
          </configuration>
      </plugin>
    </plugins>    
  </build>
  
</project>

Any ideas? I'm trying to move from monolithic Spring webapps to Spring Boot and microservices.

TIA,

Still-Learning Steve

UPDATE removing this from my Application.java

        Properties p = new Properties();
        p.setProperty( "logging.level.org.springframework", "DEBUG");
        app.setDefaultProperties(p);

leaving only

@RestController
@SpringBootApplication
public class Application {
    
    private static final DateTimeFormatter DATE_TIME_PATTERN_WITH_T_Z = DateTimeFormatter.ISO_INSTANT;          //  yyyy-MM-dd'T'HH:mm:ssZ

    java.time.Instant noww;  // implicitly UTC
    String str_noww;
    
    @RequestMapping(value={"/","/index"}, method = RequestMethod.GET)
    public ResponseEntity<Object> indexHandler( HttpServletRequest request) {
        String retStr = request.getRemoteAddr() + " pinged at " + DATE_TIME_PATTERN_WITH_T_Z.format( Instant.now());
        return new ResponseEntity<>( retStr, HttpStatus.OK );
    }

    public static void main(String[] args) {
        System.out.println("...starting SpringBootExample microservice...");
        
        SpringApplication.run( Application.class, args);
        // startup customizations go here
        

    }
}

solves the

could not find key 'context.listener.classes' in any property source

so now executing the jar does print my "...starting..." statement but still terminates moments later. Hmm.

code_warrior
  • 77
  • 10
  • Any messages in the console? Any logfiles in the working directory? – meriton Nov 08 '20 at 08:20
  • Is your @SprinBootApplication class looking like this? https://stackoverflow.com/questions/52856512/spring-boot-for-desktop-application Also, take a look at https://stackoverflow.com/questions/22380119/why-does-my-spring-boot-app-always-shutdown-immediately-after-starting – JavaMan Nov 08 '20 at 08:34

0 Answers0