|
1 | 1 | # Stand-Alone Java Server Pages with Jetty |
2 | 2 |
|
| 3 | +## 1. Introduction |
| 4 | + |
3 | 5 | [Java Server Pages](http://en.wikipedia.org/wiki/JavaServer_Pages) (JSP) are a technology for building dynamic websites with [Java](http://en.wikipedia.org/wiki/Java_(software_platform)). They are basically a mixture of [HTML](http://www.w3.org/html/) and Java code. They run in a special server, a servlet container, which compiles them to [Java Servlets](http://en.wikipedia.org/wiki/Java_Servlet), Java objects with handler routines which are called whenever a client (user) accesses the page via HTTP(S). Thus, in order to get your JSP to run, you deploy it into a servlet container, like [Tomcat](http://tomcat.apache.org/), [Jetty](http://www.eclipse.org/jetty/), or [JBoss](http://www.jboss.org/). This means you have to install the servlet container. |
4 | 6 |
|
5 | 7 | This small project is an example for how you can build a "fat" `jar` which includes both the JSPs *and* the servlet container (Jetty). This `jar` is stand-alone, i.e., you can directly run the `jar` and access the server page without any installation or deployment. |
6 | 8 |
|
7 | 9 | You can compile it with [Maven](http://maven.apache.org/) with goals `compile` and `package`. As result, you will get the `standAloneJSPs-full.jar`, which you can run via `java -jar standAloneJSPs-full.jar` without any additional requirements. It will then start the internal servlet container and then a browser to visit the entry page. In other words, different from our [deployable JSP examples](http://github.com/thomasWeise/distributedComputingExamples/tree/master/javaServerPages/examples), you do not need a servlet container. |
8 | 10 |
|
9 | | -## License |
| 11 | +## 2. Building and Deployment |
| 12 | + |
| 13 | +### 2.1. Import Project into Eclipse |
| 14 | + |
| 15 | +If you import this project in [Eclipse](http://www.eclipse.org), it may first show you a lot of errors. (I recommend using Eclipse Mars or later.) This is a Maven project, so you should "update" it first in Eclipse by |
| 16 | + |
| 17 | +1. Make sure that you can see the `package view` on the left-hand side of the Eclipse window. |
| 18 | +2. Right-click on the project (`standAloneJSPsWithJetty`) in the `package view`. |
| 19 | +3. In the opening pop-up menu, left-click on `Maven`. |
| 20 | +4. In the opening sub-menu, left-click on `Update Project...`. |
| 21 | +5. In the opening window... |
| 22 | + 1. Make sure the project (`standAloneJSPsWithJetty`) is selected. |
| 23 | + 2. Make sure that `Update project configuration from pom.xml` is selected. |
| 24 | + 3. You can also select `Clean projects`. |
| 25 | + 4. Click `OK`. |
| 26 | +6. Now the structure of the project in the `package view` should slightly change, the project will be re-compiled, and the errors should disappear. |
| 27 | + |
| 28 | + |
| 29 | +## 2.2. Build Project in Eclipse |
| 30 | + |
| 31 | +Now you can actually build the project, i.e., generate a [`jar`](https://en.wikipedia.org/wiki/JAR_%28file_format%29) file that you can directly execute on the command line and which contains both your JSPs as well as the (Jetty) servlet container: |
| 32 | + |
| 33 | +1. Make sure that you can see the `package view` on the left-hand side of the Eclipse window. |
| 34 | +2. Right-click on the project (`standAloneJSPsWithJetty`) in the `package view`. |
| 35 | +3. In the opening pop-up menu, choose `Run As`. |
| 36 | +4. In the opening sub-menu choose `Run Configurations...`. |
| 37 | +5. In the opening window, choose `Maven Build` |
| 38 | +6. In the new window `Run Configurations` / `Create, manage, and run configurations`, choose `Maven Build` in the small white pane on the left side. |
| 39 | +7. Click `New launch configuration` (the first symbol from the left on top of the small white pane). |
| 40 | +8. Write a useful name for this configuration in the `Name` field. You can use this configuration again later. |
| 41 | +9. In the tab `Main` enter the `Base directory` of the project, this is the folder called `javaServerPages/standAloneJSPsWithJetty` containing the Eclipse/Maven project. |
| 42 | +10. Under `Goals`, enter `clean compile package`. This will build a `jar` archive. |
| 43 | +11. Click `Apply` |
| 44 | +12. Click `Run` |
| 45 | +13. The build will start, you will see its status output in the console window. |
| 46 | +14. The folder `target` will contain a file `standAloneJSPs-full.jar` after the build. This is the executable archive with our application. |
| 47 | + |
| 48 | +## 3. License |
10 | 49 |
|
11 | 50 | This project is derived from [embedded-jetty-jsp](https://github.com/jetty-project/embedded-jetty-jsp) with copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd. Compared to that project, the main differences are |
12 | 51 |
|
|
0 commit comments