Class JettyMicroservice

java.lang.Object
org.apache.juneau.microservice.jetty.JettyMicroservice

public final class JettyMicroservice extends Object
Zero-config convenience launcher for a Jetty-backed Juneau microservice.

Wraps the Microservice + JettyConfiguration bootstrap in a single static call so a consumer can stand up a Jetty microservice with one Maven dependency and one line of code:

// Boot Jetty + Juneau on the default port (10000) with the interactive console enabled. public static void main(String[] args) throws Exception { JettyMicroservice.run(args, new RootResources()); }

Bundled defaults (all overridable):

  • Port 10000 (surfaced as Jetty/port in the bundled juneau.cfg).
  • Interactive console enabled (use run(String[], Servlet, boolean) with startConsole=false to suppress).
  • Classpath defaults for jetty.xml and juneau.cfg — a consumer-supplied copy on the working-directory or classpath wins via the existing Microservice resolution chain.

The supplied root servlet is registered as a @Bean Servlet in an external bean store and auto-mounted by JettyServerComponent at the path declared by its @Rest annotation. Consumers who want full control over the bean store / configuration classes / listener wiring should call Microservice.create() directly — this facade is a thin convenience over that builder.

Since:
10.0.0
  • Method Summary

    Modifier and Type
    Method
    Description
    run(String[] args, jakarta.servlet.Servlet rootServlet)
    Boots a Jetty microservice with the supplied root servlet and the bundled defaults, with the interactive console enabled.
    run(String[] args, jakarta.servlet.Servlet rootServlet, boolean startConsole)
    Boots a Jetty microservice with the supplied root servlet and the bundled defaults.
    run(String[] args, WritableBeanStore beanStore, boolean startConsole, Class<?>... configurations)
    Power-user form: boots a Jetty microservice with a caller-supplied bean store and configuration class list.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • run

      public static Microservice run(String[] args, jakarta.servlet.Servlet rootServlet) throws Exception
      Boots a Jetty microservice with the supplied root servlet and the bundled defaults, with the interactive console enabled.

      Equivalent to calling run(args, rootServlet, true).

      Parameters:
      args - The main(String[]) arguments. Forwarded to Microservice.Builder#args(String...).
      rootServlet - The root REST servlet (typically annotated with @Rest).
      Returns:
      The started Microservice instance. Callers typically chain Microservice.join().
      Throws:
      Exception - Error occurred during bootstrap.
    • run

      public static Microservice run(String[] args, jakarta.servlet.Servlet rootServlet, boolean startConsole) throws Exception
      Boots a Jetty microservice with the supplied root servlet and the bundled defaults.

      Constructs the Microservice, registers the supplied servlet as a @Bean Servlet so JettyServerComponent auto-mounts it, applies JettyConfiguration so Jetty itself is wired, and starts the lifecycle. The returned microservice has not yet been joined; callers wanting the standard "start and block forever" loop should chain .join().

      Parameters:
      args - The main(String[]) arguments. Forwarded to Microservice.Builder#args(String...).
      rootServlet - The root REST servlet (typically annotated with @Rest).
      startConsole - If true, also starts the interactive console thread via Microservice.startConsole().
      Returns:
      The started Microservice instance.
      Throws:
      Exception - Error occurred during bootstrap.
    • run

      public static Microservice run(String[] args, WritableBeanStore beanStore, boolean startConsole, Class<?>... configurations) throws Exception
      Power-user form: boots a Jetty microservice with a caller-supplied bean store and configuration class list.

      Equivalent to writing the Microservice builder chain by hand, but with the boilerplate collapsed. Use this when the simpler run(String[], Servlet) overloads are too restrictive — e.g. multiple @Bean Servlet contributions, custom MicroserviceListeners, or a parent bean store.

      Parameters:
      args - The main(String[]) arguments. Forwarded to Microservice.Builder#args(String...).
      beanStore - The bean store to use for dependency injection. Pre-populated bean entries (@Bean Servlet, MicroserviceListener, etc.) are picked up by JettyConfiguration and the microservice runtime.
      startConsole - If true, also starts the interactive console thread.
      configurations - The @Configuration-annotated classes to register. Always includes JettyConfiguration; pass an empty list to use only that.
      Returns:
      The started Microservice instance.
      Throws:
      Exception - Error occurred during bootstrap.