Skip to content

Deploying Web Apps with JDeploy

Steve Hannah edited this page Jan 2, 2017 · 4 revisions

JDeploy can be used to bundle and deploy web applications as well as executable Jars. If you provide it with a war file (or an exploded war file), it will create a self-contained application with an embedded Jetty server so that your app can be started up directly on the command-line.

Hello World Web App Example

Let’s begin by creating a simple web app that says "hello world". Suppose we have built the app and we have a hello-world.war file.

Navigate to the project directory (a directory that contains the "hello-world.war" file either directly or in one of its subdirectories) and type:

$ jdeploy init

This will generate a package.json file. Notice a couple of things about the package.json file:

  1. It will contain

    "bin" : {"hello-world" : "jdeploy-bundle/jdeploy.js"}`.

    This indicates that the command to run the app on the command line will be "helloworld".

  2. And it will also have:

    "name" : "hello-world"

    This indicates that the app would be installed using the command npm install -g hello-world. Since this "name" must be globally unique in the NPM registry, you’ll likely need to change this value to something unique like "yourdomain-hello-world".

  3. And it will mark the location of the .war file with something like:

    "jDeploy" : {
        "war" : "dist/hello-world.war"
    }

    This will be used when running jdeploy install and jdeploy publish to locate the war file to be bundled.

Now that the project is initialized, you can install the app on your local system with:

$ jdeploy install

If this completed without error, you should be able to run the app using:

$ hello-world

This will start a Jetty process to serve the app on an open port, and it will open the user’s web browser to the app so they can start interacting with it.

Once you have changed the package.json settings to your liking, you can publish the app to npm with:

$ jdeploy publish
Note
This assumes that you have an account on npm, and you are currently logged in. Creating an account takes only a couple of seconds (instructions here).

If this step completed without errors, your application is now available to install on any computer that has NodeJS installed.

Configuration Settings

The only configuration setting that is specific to web apps is the "port". If you don’t specify a port for the application, it will bind to any open port.

There are 3 ways to specify a port:

  1. In the package.json file, specify the "jDeploy/port" property to the port number that the app should bind to as a default. This may be overridden at runtime using the following command-line flags or environment variable.

  2. Using the -Djdeploy.port or -Dport command-line flags when running the app. E.g.

    $ hello-world -Dport=8080

    or

    $hello-world -Djdeploy.port=8080
  3. Using the PORT environment variable:

    $ export PORT=8080
    $ hello-world
Clone this wiki locally