Install jbang https://www.jbang.dev/download/
chmod +x Application.java
./Application.java
or
jbang Application.java
Install jbang https://www.jbang.dev/download/
chmod +x Application.java
./Application.java
or
jbang Application.java
| //usr/bin/env jbang "$0" "$@" ; exit $? | |
| // JAVA 21 | |
| // DEPS org.springframework.boot:spring-boot-dependencies:4.0.0-M1@pom | |
| // DEPS org.springframework.boot:spring-boot-starter-web | |
| // DEPS org.springframework.boot:spring-boot-starter-actuator | |
| // | |
| // JAVA_OPTIONS -Dserver.port=8080 | |
| // JAVA_OPTIONS -Dmanagement.endpoints.web.exposure.include=health,env,loggers | |
| // REPOS mavencentral | |
| package dev.ayyildiz; | |
| import java.time.LocalDateTime; | |
| import java.time.ZoneOffset; | |
| import org.springframework.boot.CommandLineRunner; | |
| import org.springframework.boot.SpringApplication; | |
| import org.springframework.boot.autoconfigure.SpringBootApplication; | |
| import org.springframework.web.bind.annotation.*; | |
| import org.springframework.web.bind.annotation.RestController; | |
| @SpringBootApplication | |
| public class Application { | |
| public static void main(String[] args) { | |
| SpringApplication.run(Application.class, args); | |
| } | |
| } | |
| record Time(String currentTime, long epoch) {} | |
| @RestController | |
| @RequestMapping("/api") | |
| class ApiController { | |
| @GetMapping("/time") | |
| public Time getTime() { | |
| var currentTime = LocalDateTime.now().toString(); | |
| var epoch = LocalDateTime.now().toEpochSecond(ZoneOffset.UTC); | |
| return new Time(currentTime, epoch); | |
| } | |
| } | |
| @RestController | |
| class HealthController { | |
| @GetMapping("/health") | |
| public String getHealth() { | |
| return "Healthy"; | |
| } | |
| } |