What Is Jetty
Pages: 1, 2, 3, 4
The Executable JAR
If you embrace Jetty's XML to configure your own apps, you could end up with a lot of boilerplate code to load the config file and launch your stand-alone apps. You can use Jetty's executable start.jar to load the file for you, saving you even more code.
For example, you can load the Jetty-based service from Step2Driver using the following command line:
CLASSPATH= ...various Jetty JARs...
java \
-Djetty.class.path=${CLASSPATH} \
-jar <jetty install path>/start.jar \
standalone.xml
Note that this call only loads the XML file to establish the container and listener. It, therefore, doesn't call the rest of the sample code that invokes the test URLs.
Conclusion
An embedded Jetty servlet container lets you web enable a Java app without having to package it as a formal web app. This opens up new possibilities for several disciplines, making Jetty a versatile addition to your toolbox.
There is certainly more to Jetty than I have written here. I encourage you to review the Jetty website for docs and sample code.
Resources
- Sample code for this article .
- The Jetty website has links to documentation, samples, and downloads. It includes the "Jetty Powered" page, which has links to some apps that have somehow incorporated Jetty. Also of note is the JettyPlus subproject, which offers support for JNDI, DataSources, and other features beyond the servlet spec.
- Sun's Java EE website, which has links to the servlet spec .
- Java Reflection in Action discusses Java's Reflection and Introspection APIs in detail.
- For the sake of comparison, OnJava has also published an article on Tomcat's embedded side.
- I mentioned Swing, XUI, and SWT as Java-based options for GUI front ends.
- The Message-Driven Bank is from another OnJava article, "J2EE Without the Application Server."
Q Ethan McCallum grew from curious child to curious adult, turning his passion for technology into a career.
Return to ONJava.com.