{title:'Installing in Eclipse', created:'8.0.0'}

Follow these instructions to create a new template project in Eclipse.

1. Download the my-jetty-microservice-9.0.1.zip file from the downloads page (located in the binaries) and import it into your workspace as an existing project:
2. Select the archive file and import the project:
3. In your workspace, you should now see the following project:

The important elements in this project are:

- App.java - The entry point.
  This class creates and starts our microservice:

  | public class App { | | public static void main(String[] args) throws Exception { | JettyMicroservice | .create() | .args(args) | .servlet(RootResources.class) | .build() | .start() | .startConsole() | .join(); | } | }

- RootResources.java - The top-level REST resource.
  This class routes HTTP requests to child resources:

  | @Rest( | path="/", | title="My Microservice", | description="Top-level resources page", | children={ | HelloWorldResource.class, | ConfigResource.class, | LogsResource.class | } | ) | @HtmlDocConfig( | widgets={ | ContentTypeMenuItem.class, | StyleMenuItem.class | }, | navlinks={ | "options: servlet:/?method=OPTIONS" | } | ) | public class RootResources extends BasicRestServletGroup { | // No code | }

- mjm.cfg - The external configuration file.
  Contains various useful settings.
  Can be used for your own resource configurations.

  | #======================================================================================================================= | # Basic configuration file for REST microservices | # Subprojects can use this as a starting point. | #======================================================================================================================= | | #======================================================================================================================= | # Jetty settings | #======================================================================================================================= | [Jetty] | | # Path of the jetty.xml file used to configure the Jetty server. | config = jetty.xml | | # Resolve Juneau variables in the jetty.xml file. | resolveVars = true | | # Port to use for the jetty server. | # You can specify multiple ports. The first available will be used. '0' indicates to try a random port. | # The resulting available port gets set as the system property "availablePort" which can be referenced in the | # jetty.xml file as "$S{availablePort}" (assuming resolveVars is enabled). | port = 10000,0,0,0 | | # Optionally specify your servlets here: | #servlets = org.apache.juneau.microservice.sample.RootResources | | #======================================================================================================================= | # REST settings | #======================================================================================================================= | [REST] | | # Comma-delimited list of key-value pairs that represent locations of static files that can be served up by your @Rest-annotated | # classes. These are static files that are served up by the servlet under the specified sub-paths. | # For example, given the following setting... | # staticFiles = htdocs:my-docs,styles/my-styles | # ...the URI "/servletPath/htdocs/javadoc.css" resolves to the path "/my-docs/javadoc.css". | # This path can be relative to the working directory, classpath root, or package of your resource class. | # Used by the BasicRestConfig interface that defines the following value: | # staticFiles="$C{REST/staticFiles}" | staticFiles = htdocs:htdocs | | # Stylesheet to use for HTML views. | # Used by the BasicRestConfig interface that defines the following value: | # stylesheet="$C{REST/theme,servlet:/htdocs/themes/devops.css}" | theme = servlet:/htdocs/themes/devops.css | | # Various look-and-feel settings used in the BasicRestConfig interface. | headerIcon = servlet:/htdocs/images/juneau.png | headerLink = http://juneau.apache.org | footerIcon = servlet:/htdocs/images/asf.png | footerLink = http://www.apache.org | favicon = $C{REST/headerIcon} | header = | <a href='$U{$C{REST/headerLink}}'> | <img src='$U{$C{REST/headerIcon}}' style='position:absolute;top:5;right:5;background-color:transparent;height:30px'/> | </a> | footer = | <a href='$U{$C{REST/footerLink}}'> | <img src='$U{$C{REST/footerIcon}}' style='float:right;padding-right:20px;height:32px'/> | </a> | | #======================================================================================================================= | # Console settings | #======================================================================================================================= | [Console] | | enabled = true | | # List of available console commands. | # These are classes that implements ConsoleCommand that allow you to submit commands to the microservice via | # the console. | # When listed here, the implementations must provide a no-arg constructor. | # They can also be provided dynamically by overriding the Microservice.createConsoleCommands() method. | commands = | org.apache.juneau.microservice.console.ExitCommand, | org.apache.juneau.microservice.console.RestartCommand, | org.apache.juneau.microservice.console.HelpCommand, | org.apache.juneau.microservice.console.ConfigCommand | | #======================================================================================================================= | # Logger settings | #----------------------------------------------------------------------------------------------------------------------- | # See FileHandler Java class for details. | #======================================================================================================================= | [Logging] | | ... | | #======================================================================================================================= | # System properties | #----------------------------------------------------------------------------------------------------------------------- | # These are arbitrary system properties that are set during startup. | #======================================================================================================================= | [SystemProperties] | | # Configure Jetty for StdErrLog Logging | # org.eclipse.jetty.util.log.class = org.eclipse.jetty.util.log.StrErrLog | | # Configure Jetty to log using java-util logging | org.eclipse.jetty.util.log.class = org.apache.juneau.microservice.jetty.JettyLogger | | # Jetty logging level | # Possible values: ALL, DEBUG, INFO, WARN, OFF | org.eclipse.jetty.LEVEL = WARN | | derby.stream.error.file = $C{Logging/logDir}/derby-errors.log

- jetty.xml - The Jetty configuration file.
  A bare-bones config file that can be extended to use any Jetty features.

  | <Configure id="ExampleServer" class="org.eclipse.jetty.server.Server"> | | <Set name="connectors"> | <Array type="org.eclipse.jetty.server.Connector"> | <Item> | <New class="org.eclipse.jetty.server.ServerConnector"> | <Arg> | <Ref refid="ExampleServer"/> | </Arg> | <Set name="port">$S{availablePort,8080}</Set> | </New> | </Item> | </Array> | </Set> | | <New id="context" class="org.eclipse.jetty.ee9.servlet.ServletContextHandler"> | <Set name="contextPath">/</Set> | <!-- Optionally specify your servlets here --> | <!--Call name="addServlet"> | <Arg>org.apache.juneau.microservice.sample.RootResources</Arg> | <Arg>/*</Arg> | </Call--> | <Set name="sessionHandler"> | <New class="org.eclipse.jetty.ee9.nested.SessionHandler"/> | </Set> | </New> | | <Set name="handler"> | <New class="org.eclipse.jetty.ee9.nested.HandlerCollection"> | <Set name="handlers"> | <Array type="org.eclipse.jetty.ee9.nested.Handler"> | <Item> | <Ref refid="context"/> | </Item> | <Item> | <New class="org.eclipse.jetty.server.handler.DefaultHandler"/> | </Item> | </Array> | </Set> | </New> | </Set> | | <New id="RequestLogImpl" class="org.eclipse.jetty.server.CustomRequestLog"> | <!-- Param 0: org.eclipse.jetty.server.RequestLogWriter --> | <Arg> | <New class="org.eclipse.jetty.server.RequestLogWriter"> | <Set name="append">false</Set>; | <Set name="filename"><Property name="jetty.logs" default="$C{Logging/logDir,logs}" />/jetty-requests.log</Set>; | <Set name="filenameDateFormat">yyyy_MM_dd</Set> | <Set name="retainDays">90</Set> | <Set name="timeZone">GMT</Set> | </New> | </Arg> | <!-- Param 1: String --> | <Arg> | <Get class="org.eclipse.jetty.server.CustomRequestLog" name="EXTENDED_NCSA_FORMAT" /> | </Arg> | </New> | | <Get name="ThreadPool"> | <Set name="minThreads" type="int">10</Set> | <Set name="maxThreads" type="int">100</Set> | <Set name="idleTimeout" type="int">60000</Set> | <Set name="detailedDump">true</Set> | </Get> | </Configure>

At this point, you're ready to start the microservice from your workspace.