| <!-- |
| /*************************************************************************************************************************** |
| * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file |
| * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file |
| * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance |
| * with the License. You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| * specific language governing permissions and limitations under the License. |
| ***************************************************************************************************************************/ |
| --> |
| |
| {title:'Installing in Eclipse', created:'8.0.0'} |
| |
| <div class='topic'> |
| <p> |
| Follow these instructions to create a new template project in Eclipse. |
| </p> |
| <ol class='spaced-list'> |
| <li> |
| Download the <c>my-jetty-microservice-<juneauVersion>9.0.1</juneauVersion>.zip</c> file from the downloads page |
| (located in the binaries) and import it into your workspace as an existing project: |
| <br><br> |
| <img class='bordered' src='doc-files/mjm.Installing.1.png' style='width:524px'> |
| <li> |
| Select the archive file and import the project: |
| <br><br> |
| <img class='bordered' src='doc-files/mjm.Installing.2.png' style='width:549px'> |
| <li> |
| In your workspace, you should now see the following project: |
| <br><br> |
| <img class='bordered' src='doc-files/mjm.Installing.3.png' style='width:400px'> |
| </ol> |
| <p> |
| The important elements in this project are: |
| </p> |
| <ul class='spaced-list'> |
| <li> |
| <l>App.java</l> - The entry point. |
| <br>This class creates and starts our microservice: |
| <br><br> |
| <p class='bjava'> |
| | <jk>public class</jk> App { |
| | |
| | <jk>public static void</jk> main(String[] <jv>args</jv>) <jk>throws</jk> Exception { |
| | JettyMicroservice |
| | .<jsm>create</jsm>() |
| | .args(<jv>args</jv>) |
| | .servlet(RootResources.<jk>class</jk>) |
| | .build() |
| | .start() |
| | .startConsole() |
| | .join(); |
| | } |
| | } |
| </p> |
| <li> |
| <l>RootResources.java</l> - The top-level REST resource. |
| <br>This class routes HTTP requests to child resources: |
| <br><br> |
| <p class='bjava'> |
| | <ja>@Rest</ja>( |
| | path=<js>"/"</js>, |
| | title=<js>"My Microservice"</js>, |
| | description=<js>"Top-level resources page"</js>, |
| | children={ |
| | HelloWorldResource.<jk>class</jk>, |
| | ConfigResource.<jk>class</jk>, |
| | LogsResource.<jk>class</jk> |
| | } |
| | ) |
| | <ja>@HtmlDocConfig</ja>( |
| | widgets={ |
| | ContentTypeMenuItem.<jk>class</jk>, |
| | StyleMenuItem.<jk>class</jk> |
| | }, |
| | navlinks={ |
| | <js>"options: servlet:/?method=OPTIONS"</js> |
| | } |
| | ) |
| | <jk>public class</jk> RootResources <jk>extends</jk> BasicRestServletGroup { |
| | <jc>// No code</jc> |
| | } |
| </p> |
| <li> |
| <l>mjm.cfg</l> - The external configuration file. |
| <br>Contains various useful settings. |
| <br>Can be used for your own resource configurations. |
| <br><br> |
| <p class='bini'> |
| | <cc>#======================================================================================================================= |
| | # Basic configuration file for REST microservices |
| | # Subprojects can use this as a starting point. |
| | #=======================================================================================================================</cc> |
| | |
| | <cc>#======================================================================================================================= |
| | # Jetty settings |
| | #=======================================================================================================================</cc> |
| | <cs>[Jetty]</cs> |
| | |
| | <cc># Path of the jetty.xml file used to configure the Jetty server.</cc> |
| | <ck>config</ck> = <cv>jetty.xml</cv> |
| | |
| | <cc># Resolve Juneau variables in the jetty.xml file.</cc> |
| | <ck>resolveVars</ck> = <cv>true</cv> |
| | |
| | <cc># 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).</cc> |
| | <ck>port</ck> = <cv>10000,0,0,0</cv> |
| | |
| | <cc># Optionally specify your servlets here: |
| | #servlets = org.apache.juneau.microservice.sample.RootResources</cc> |
| | |
| | <cc>#======================================================================================================================= |
| | # REST settings |
| | #=======================================================================================================================</cc> |
| | <cs>[REST]</cs> |
| | |
| | <cc># 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}"</cc> |
| | <ck>staticFiles</ck> = htdocs:htdocs |
| | |
| | <cc># 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}"</cc> |
| | <ck>theme</ck> = <cv>servlet:/htdocs/themes/devops.css</cv> |
| | |
| | <cc># Various look-and-feel settings used in the BasicRestConfig interface.</cc> |
| | <ck>headerIcon</ck> = <cv>servlet:/htdocs/images/juneau.png</cv> |
| | <ck>headerLink</ck> = <cv>http://juneau.apache.org</cv> |
| | <ck>footerIcon</ck> = <cv>servlet:/htdocs/images/asf.png</cv> |
| | <ck>footerLink</ck> = <cv>http://www.apache.org</cv> |
| | <ck>favicon</ck> = <cv>$C{REST/headerIcon}</cv> |
| | <ck>header</ck> = |
| | <cv><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></cv> |
| | <ck>footer</ck> = |
| | <cv><a href='$U{$C{REST/footerLink}}'> |
| | <img src='$U{$C{REST/footerIcon}}' style='float:right;padding-right:20px;height:32px'/> |
| | </a></cv> |
| | |
| | <cc>#======================================================================================================================= |
| | # Console settings |
| | #=======================================================================================================================</cc> |
| | <cs>[Console]</cs> |
| | |
| | <ck>enabled</ck> = <cv>true</cv> |
| | |
| | <cc># 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.</cc> |
| | <ck>commands</ck> = |
| | <cv>org.apache.juneau.microservice.console.ExitCommand, |
| | org.apache.juneau.microservice.console.RestartCommand, |
| | org.apache.juneau.microservice.console.HelpCommand, |
| | org.apache.juneau.microservice.console.ConfigCommand</cv> |
| | |
| | <cc>#======================================================================================================================= |
| | # Logger settings |
| | #----------------------------------------------------------------------------------------------------------------------- |
| | # See FileHandler Java class for details. |
| | #=======================================================================================================================</cc> |
| | <cs>[Logging]</cs> |
| | |
| | ... |
| | |
| | <cc>#======================================================================================================================= |
| | # System properties |
| | #----------------------------------------------------------------------------------------------------------------------- |
| | # These are arbitrary system properties that are set during startup. |
| | #=======================================================================================================================</cc> |
| | <cs>[SystemProperties]</cs> |
| | |
| | <cc># Configure Jetty for StdErrLog Logging |
| | # org.eclipse.jetty.util.log.class = org.eclipse.jetty.util.log.StrErrLog</cc> |
| | |
| | <cc># Configure Jetty to log using java-util logging</cc> |
| | <ck>org.eclipse.jetty.util.log.class</ck> = <cv>org.apache.juneau.microservice.jetty.JettyLogger</cv> |
| | |
| | <cc># Jetty logging level |
| | # Possible values: ALL, DEBUG, INFO, WARN, OFF</cc> |
| | <ck>org.eclipse.jetty.LEVEL</ck> = <cv>WARN |
| | |
| | <ck>derby.stream.error.file</ck> = <cv>$C{Logging/logDir}/derby-errors.log</cv> |
| </p> |
| <li> |
| <l>jetty.xml</l> - The Jetty configuration file. |
| <br>A bare-bones config file that can be extended to use any Jetty features. |
| <br><br> |
| <p class='bxml'> |
| | <xt><Configure</xt> <xa>id</xa>=<xs>"ExampleServer"</xs> <xa>class</xa>=<xs>"org.eclipse.jetty.server.Server"</xs>></xt> |
| | |
| | <xt><Set</xt> <xa>name</xa>=<xs>"connectors"</xs><xt>></xt> |
| | <xt><Array</xt> <xa>type</xa>=<xs>"org.eclipse.jetty.server.Connector"</xs><xt>></xt> |
| | <xt><Item></xt> |
| | <xt><New</xt> <xa>class</xa>=<xs>"org.eclipse.jetty.server.ServerConnector"</xs><xt>></xt> |
| | <xt><Arg></xt> |
| | <xt><Ref</xt> <xa>refid</xa>=<xs>"ExampleServer"</xs><xt>/></xt> |
| | <xt></Arg></xt> |
| | <xt><Set</xt> <xa>name</xa>=<xs>"port"</xs><xt>></xt>$S{availablePort,8080}<xt></Set></xt> |
| | <xt></New></xt> |
| | <xt></Item></xt> |
| | <xt></Array></xt> |
| | <xt></Set></xt> |
| | |
| | <xt><New</xt> <xa>id</xa>=<xs>"context"</xs> <xa>class</xa>=<xs>"org.eclipse.jetty.ee9.servlet.ServletContextHandler"</xs><xt>></xt> |
| | <xt><Set</xt> <xa>name</xa>=<xs>"contextPath"</xs><xt>>/</Set></xt> |
| | <xc><!-- Optionally specify your servlets here --> |
| | <!--Call name="addServlet"> |
| | <Arg>org.apache.juneau.microservice.sample.RootResources</Arg> |
| | <Arg>/*</Arg> |
| | </Call--></xc> |
| | <xt><Set</xt> <xa>name</xa>=<xs>"sessionHandler"</xs><xt>></xt> |
| | <xt><New</xt> <xa>class</xa>=<xs>"org.eclipse.jetty.ee9.nested.SessionHandler"</xs><xt>/></xt> |
| | <xt></Set></xt> |
| | <xt></New></xt> |
| | |
| | <xt><Set</xt> <xa>name</xa>=<xs>"handler"</xs><xt>></xt> |
| | <xt><New</xt> <xa>class</xa>=<xs>"org.eclipse.jetty.ee9.nested.HandlerCollection"</xs><xt>></xt> |
| | <xt><Set</xt> <xa>name</xa>=<xs>"handlers"</xs><xt>></xt> |
| | <xt><Array</xt> <xa>type</xa>=<xs>"org.eclipse.jetty.ee9.nested.Handler"</xs><xt>></xt> |
| | <xt><Item></xt> |
| | <xt><Ref</xt> <xa>refid</xa>=<xs>"context"</xs><xt>/></xt> |
| | <xt></Item></xt> |
| | <xt><Item></xt> |
| | <xt><New</xt> <xa>class</xa>=<xs>"org.eclipse.jetty.server.handler.DefaultHandler"</xs><xt>/></xt> |
| | <xt></Item></xt> |
| | <xt></Array></xt> |
| | <xt></Set></xt> |
| | <xt></New></xt> |
| | <xt></Set></xt> |
| | |
| | <xt><New</xt> <xa>id</xa>=<xs>"RequestLogImpl"</xs> <xa>class</xa>=<xs>"org.eclipse.jetty.server.CustomRequestLog"</xs><xt>></xt> |
| | <xc><!-- Param 0: org.eclipse.jetty.server.RequestLogWriter --></xc> |
| | <xt><Arg></xt> |
| | <xt><New</xt> <xa>class</xa>=<xs>"org.eclipse.jetty.server.RequestLogWriter"</xs><xt>></xt> |
| | <xt><Set</xt> <xa>name</xa>=<xs>"append"</xs><xt>></xt>false<xt></Set></xt>; |
| | <xt><Set</xt> <xa>name</xa>=<xs>"filename"</xs><xt>><Property</xt> <xa>name</xa>=<xs>"jetty.logs"</xs> <xa>default</xa>=<xs>"$C{Logging/logDir,logs}"</xs> <xt>/></xt>/jetty-requests.log<xt></Set></xt>; |
| | <xt><Set</xt> <xa>name</xa>=<xs>"filenameDateFormat"</xs><xt>></xt>yyyy_MM_dd<xt></Set></xt> |
| | <xt><Set</xt> <xa>name</xa>=<xs>"retainDays"</xs><xt>></xt>90<xt></Set></xt> |
| | <xt><Set</xt> <xa>name</xa>=<xs>"timeZone"</xs><xt>></xt>GMT<xt></Set></xt> |
| | <xt></New></xt> |
| | <xt></Arg></xt> |
| | <xc><!-- Param 1: String --></xc> |
| | <xt><Arg></xt> |
| | <xt><Get</xt> <xa>class</xa>=<xs>"org.eclipse.jetty.server.CustomRequestLog"</xs> <xa>name</xa>=<xs>"EXTENDED_NCSA_FORMAT"</xs> <xt>/></xt> |
| | <xt></Arg></xt> |
| | <xt></New></xt> |
| | |
| | <xt><Get</xt> <xa>name</xa>=<xs>"ThreadPool"</xs><xt>></xt> |
| | <xt><Set</xt> <xa>name</xa>=<xs>"minThreads"</xs> <xa>type</xa>=<xs>"int"</xs><xt>></xt>10<xt></Set></xt> |
| | <xt><Set</xt> <xa>name</xa>=<xs>"maxThreads"</xs> <xa>type</xa>=<xs>"int"</xs><xt>></xt>100<xt></Set></xt> |
| | <xt><Set</xt> <xa>name</xa>=<xs>"idleTimeout"</xs> <xa>type</xa>=<xs>"int"</xs><xt>></xt>60000<xt></Set></xt> |
| | <xt><Set</xt> <xa>name</xa>=<xs>"detailedDump"</xs><xt>></xt>true<xt></Set></xt> |
| | <xt></Get></xt> |
| | <xt></Configure></xt> |
| </p> |
| </ul> |
| <p> |
| At this point, you're ready to start the microservice from your workspace. |
| </p> |
| </div> |