Basically you can run jetty in two different modes:
- Interactively: use s.th. like
buildr yourproject:run-jettyand have the jetty running within this shell, so that you see the output of jetty and your app
- In the background: use
buildr yourproject:deploy-appto 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:
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 ). 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
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: