Child pages
  • How to run jetty
Skip to end of metadata
Go to start of metadata

*

*


Basically you can run jetty in two different modes:

  1. Interactively: use s.th. like buildr yourproject:run-jetty and have the jetty running within this shell, so that you see the output of jetty and your app
  2. In the background: use buildr jetty:start and buildr yourproject:deploy-app to start jetty in the background and deploy your app. The build is not blocking in this case and you can use your shell for different things.

Run jetty interactively

In your buildfile you define the jetty task within your project (here it's "webapp"):

If you prefer to use CTRL-C to stop jetty instead of hitting ENTER you can replace the Readline::... line with this:

Then you can run your webapplication inside jetty:

That's all

Start jetty in the background

In your buildfile you define the "deploy-app" task within your project (here it's "webapp"):

Now, in one console do:

Switch to a different console and do:

Now the app is running and you can access it from the browser. The first console is effectively the Jetty log, and you kill Jetty at any time by going there and hitting CTRL-C. The second console gives you a new prompt and you can run buildr deploy-app again, test the app using curl, etc.

Alternatively, in a single console:

And again this free up the console so you can do more work while your app is running inside Jetty.

To stop the server:

Run several jetty instances in different modules

If you have a multi module project with several web applications (producing a war) you might want to start them in different jetty instances (on different ports).

To achieve this you cannot use the default jetty singleton instance (as shown in the examples above) but you must create a new jetty instance for the different web applications (or at least starting with the second (smile)). The following example demonstrates this:

Now you can start both jetty instances in parallel.
Starting jetty for the first subproject:

And after the subprojA jetty was started (or in a different console):

Run embedded jetty on working directory

The suggestions above will always have you run through a complete compile -> package -> deploy cycle, even if you are only editing Javascript files or did a minor small change in a sub project, which gets annoying pretty fast. Use the embedded server and run it directly on your working directory instead to save all that packaging time and to edit HTML in place.

Add a source file to start embedded jetty using your webapp configuration (Scala code here, but you can change that to Java easily):

Next add a run task inside of your project:

This will set up your class path with the compile dependencies and run the java command with your server class.

Starting the application:

That's it.

  • No labels