//
//  ========================================================================
//  Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//  ========================================================================
//  All rights reserved. This program and the accompanying materials
//  are made available under the terms of the Eclipse Public License v1.0
//  and Apache License v2.0 which accompanies this distribution.
//
//      The Eclipse Public License is available at
//      http://www.eclipse.org/legal/epl-v10.html
//
//      The Apache License v2.0 is available at
//      http://www.opensource.org/licenses/apache2.0.php
//
//  You may elect to redistribute this code under either of these licenses.
//  ========================================================================
//

[[startup-classpath]]
=== Managing Server Classpath

Jetty Server Classpath is determined by a combination of factors.

The java.class.path System Property::
  If you start Jetty with a JVM specified classpath, then Jetty will use the java.class.path System Property to populate the initial classpath.
Module specified Libraries::
  The module system declares various libraries that are required for that module to operate.
  These module defined libraries are added to the Jetty Server classpath when any module is activated with library declarations.
Command Line Libraries::
  The command line option `--lib=<path>` can be used as a final means to add arbitrary entries to the Jetty Server classpath.

Of special note, there are 2 structural modules defined to ease some of this for you.

--module=ext::
  The `ext` module will enable the `lib/ext/*.jar` logic.
  +
  If this module is activated, then all jar files found in the lib/ext/ paths will be automatically added to the Jetty Server Classpath.
--module=resources::
  The `resources` module will add the `resources/` directory the classpath.
  +
  If you have 3rd party libraries that lookup resources from the classpath, put your files in here.
  +
  Logging libraries often have classpath lookup of their configuration files (eg: `log4j.properties`, `log4j.xml`, `logging.properties`, and `logback.xml`), so this would be the ideal setup for this sort of configuration demand.

____
[NOTE]
Both the `ext` and `resources` modules declare relative paths that follow link:#base-vs-home-resolution[Jetty Base and Jetty Home path resolution rules].
____

==== Interrogating the Server Classpath

The Jetty `start.jar` has the ability to resolve the classpath from the command line, modules and configuration, and to list the classpath entries it will use to start jetty.

The `--list-classpath` command line option is used as such.

(Demonstrated with the link:#demo-base[demo-base from the Jetty Distribution])

[source, screen, subs="{sub-order}"]
....
[demo-base]$ java -jar $JETTY_HOME/start.jar --list-classpath

Jetty Server Classpath:
-----------------------
Version Information on 42 entries in the classpath.
Note: order presented here is how they would appear on the classpath.
      changes to the --module=name command line options will be reflected here.
 0:               {VERSION} | ${jetty.home}/lib/jetty-client-{VERSION}.jar
 1:      1.4.1.v201005082020 | ${jetty.base}/lib/ext/javax.mail.glassfish-1.4.1.v201005082020.jar
 2:               {VERSION} | ${jetty.base}/lib/ext/test-mock-resources-{VERSION}.jar
 3:                    (dir) | ${jetty.home}/resources
 4:                    3.1.0 | ${jetty.home}/lib/servlet-api-3.1.jar
 5:                  3.1.RC0 | ${jetty.home}/lib/jetty-schemas-3.1.jar
 6:               {VERSION} | ${jetty.home}/lib/jetty-http-{VERSION}.jar
 7:               {VERSION} | ${jetty.home}/lib/jetty-continuation-{VERSION}.jar
 8:               {VERSION} | ${jetty.home}/lib/jetty-server-{VERSION}.jar
 9:               {VERSION} | ${jetty.home}/lib/jetty-xml-{VERSION}.jar
10:               {VERSION} | ${jetty.home}/lib/jetty-util-{VERSION}.jar
11:               {VERSION} | ${jetty.home}/lib/jetty-io-{VERSION}.jar
12:               {VERSION} | ${jetty.home}/lib/jetty-jaas-{VERSION}.jar
13:               {VERSION} | ${jetty.home}/lib/jetty-jndi-{VERSION}.jar
14:      1.1.0.v201105071233 | ${jetty.home}/lib/jndi/javax.activation-1.1.0.v201105071233.jar
15:      1.4.1.v201005082020 | ${jetty.home}/lib/jndi/javax.mail.glassfish-1.4.1.v201005082020.jar
16:                      1.3 | ${jetty.home}/lib/jndi/javax.transaction-api-1.3.jar
17:               {VERSION} | ${jetty.home}/lib/jetty-rewrite-{VERSION}.jar
18:               {VERSION} | ${jetty.home}/lib/jetty-security-{VERSION}.jar
19:               {VERSION} | ${jetty.home}/lib/jetty-servlet-{VERSION}.jar
20:                    3.0.0 | ${jetty.home}/lib/jsp/javax.el-3.0.0.jar
21:      1.2.0.v201105211821 | ${jetty.home}/lib/jsp/javax.servlet.jsp.jstl-1.2.0.v201105211821.jar
22:                    2.3.2 | ${jetty.home}/lib/jsp/javax.servlet.jsp-2.3.2.jar
23:                    2.3.1 | ${jetty.home}/lib/jsp/javax.servlet.jsp-api-2.3.1.jar
24:                    2.3.3 | ${jetty.home}/lib/jsp/jetty-jsp-jdt-2.3.3.jar
25:      1.2.0.v201112081803 | ${jetty.home}/lib/jsp/org.apache.taglibs.standard.glassfish-1.2.0.v201112081803.jar
26:   3.8.2.v20130121-145325 | ${jetty.home}/lib/jsp/org.eclipse.jdt.core-3.8.2.v20130121.jar
27:               {VERSION} | ${jetty.home}/lib/jetty-plus-{VERSION}.jar
28:               {VERSION} | ${jetty.home}/lib/jetty-webapp-{VERSION}.jar
29:               {VERSION} | ${jetty.home}/lib/jetty-annotations-{VERSION}.jar
30:                      4.1 | ${jetty.home}/lib/annotations/asm-4.1.jar
31:                      4.1 | ${jetty.home}/lib/annotations/asm-commons-4.1.jar
32:                      1.2 | ${jetty.home}/lib/annotations/javax.annotation-api-1.2.jar
33:               {VERSION} | ${jetty.home}/lib/jetty-deploy-{VERSION}.jar
34:                      1.0 | ${jetty.home}/lib/websocket/javax.websocket-api-1.0.jar
35:               {VERSION} | ${jetty.home}/lib/websocket/javax-websocket-client-impl-{VERSION}.jar
36:               {VERSION} | ${jetty.home}/lib/websocket/javax-websocket-server-impl-{VERSION}.jar
37:               {VERSION} | ${jetty.home}/lib/websocket/websocket-api-{VERSION}.jar
38:               {VERSION} | ${jetty.home}/lib/websocket/websocket-client-{VERSION}.jar
39:               {VERSION} | ${jetty.home}/lib/websocket/websocket-common-{VERSION}.jar
40:               {VERSION} | ${jetty.home}/lib/websocket/websocket-server-{VERSION}.jar
41:               {VERSION} | ${jetty.home}/lib/websocket/websocket-servlet-{VERSION}.jar
....

Of note is that an attempt is made to list the internally declared version of each artifact on the Server Classpath, which can potentially help when diagnosing classpath issues.
