Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Spring Boot Headless

Tags:

spring-boot

I have a spring boot application and I would like to run it headless. When I run from the terminal this is the command I'm using:

java -jar myapp.jar --spring.main.headless=true

Is this correct? Any help is well appreciated.

like image 377
Joe Avatar asked May 08 '14 22:05

Joe


People also ask

What is JDK headless?

Headless mode is a system configuration in which the display device, keyboard, or mouse is lacking. Sounds unexpected, but actually you can perform different operations in this mode, even with graphic data.

What is Djava AWT headless true?

Headless mode This means that your Java application does not display windows or dialog boxes, does not accept keyboard or mouse input, and does not use any heavyweight AWT components. This mode is selected by specifying Java property java. awt. headless=true on the Java invocation.

What is headless exception in Java?

HeadlessException is a runtime exception in Java that occurs when code that is dependent on a keyboard, display or mouse is called in an environment that does not support a keyboard, display or mouse.


2 Answers

I've faced with same problem and solved it using SpringApplicationBuilder class. You should set headless false (which is true by default). See javadoc.

My main method looks like this:

  public static void main(String[] args) {
    SpringApplicationBuilder builder = new SpringApplicationBuilder(App.class);
    builder.headless(false).run(args);
  }
like image 192
Efe Kahraman Avatar answered Sep 29 '22 00:09

Efe Kahraman


The spring.main.* properties are injected into the SpringApplication. It doesn't know anything about heads or headlessness. Maybe you need java -Djava.awt.headless=true ...?

like image 34
Dave Syer Avatar answered Sep 29 '22 00:09

Dave Syer