package.json Reference

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

jDeploy uses the package.json file to store all of its configuration details for a project. When you run jdeploy init it will create a default package.json file in the current working directory with default settings.

Note
For full documentation on the package.json file and its standard properties, see the npm package.json documentation.

Most of the jDeploy-related settings are located inside the "jDeploy" object. E.g.

{
    ...
    "jDeploy" : {
        "jar" : "dist/my-app.jar"
        ...
    }
}

However, there are a few properties at the "root" level that will affect how jDeploy deploys your application.

Main Root-Level Properties

The following standard properties are important to jDeploy.

Property Description Required Default

name

The name used to install your app from NPM. This must be unique in the NPM registry. E.g. If your "name" is

Yes

bin

An map containing the binaries for your application. This must contain at least one entry whose key is the name of your app as it will be called on the command-line, and value is "jdeploy-bundle/jdeploy.js"

Yes

dependencies

Must include a dependency on the "shelljs" library. "dependencies": {"shelljs": "^0.7.5"}

Yes

For other root-level properties see npm package.json documentation

Basic jDeploy Object Properties

The following properties should be placed inside the "jDeploy" object of the package.json, and are almost always used.

Property Description Required Default

jar

Relative path to the executable jar file that contains your app. You should supply either "war" or "jar", but not both. This value may be the path to a file, or a glob pattern (e.g. using * and ?) that can be used to match a file.

No

war

Relative path to a war file, or web-app directory that contains your web app. You should supply either "war" or "jar", but not both. This value may be the path to a file, or a glob pattern (e.g. using * and ?) that can be used to match a file.

No

Advanced jDeploy Object Properties

The following properties may be placed in the "jDeploy" object of the package.json file.

Property Description Required Default

files

List of copy rules for copying files into the the deployed application bundle. By default, for executable jar deployments, it will copy the jar file and all files listed in the jar’s class path (from its manifest file); and for war deployments, it will just copy what is inside the war file. If you need additional files to be deployed (e.g. native libs or resources), then you should specify them in this list. See Copy Rules.

No

port

For war deployments, this specifies the port that the Jetty wrapper should bind to. This can be overridden at runtime using the -Djdeploy.port or -Dport command-line flags, or via the PORT environment variable. If this option is omitted, and no port is specified at runtime, it will use "0" as the port, which will cause it to bind to a random open port.

No

0

antFile

Set the ant build file to use for the preCopyTarget and postCopyTarget options.

No

build.xml

preCopyTarget

You can optionally specify ANT to run a target before copying files to the jdeploy-bundle directory. You can specify the ant build script that contains the target using the antFile property.

No

postCopyTarget

Optional ANT target to be run after files have been copied to the jdeploy-bundle directory. You can specify the ant build script that contains the target using the antFile property.

No

preCopyScript

Optional script to be executed before copying files to the jdeploy-bundle directory.

No

postCopyScript

Optional script to be executed after copying files to the jdeploy-bundle directory.

No

Copy Rules

The "jDeploy/files" array includes zero or more copy rules. Each copy rule is an object that may contain the following properties:

Property Description Required Default

dir

The relative path to the directory from which files are to be copied.

Yes

includes

Specifies files to be included in the copy. Either an array of glob patterns, or a comma-delimited string of glob patterns. The glob pattern uses PathMatcher globs. E.g. "*/.dll".

No

All files in dir

excludes

Specifies files to be excluded from the copy. Either an array of glob patterns, or a comma-delimited string of glob patterns. The glob pattern uses PathMatcher globs.

No

None

Example Copy Rules*

{
  ...
  "jDeploy" : {
    "files" : [
        {"dir" : "dist", "includes": "lib/*.dll,lib/*.so,lib/*.dylib"}
    ]
  }
  ...
}

This would copy all of the dll, so, and dylib files from "dist/lib" into the jdeploy-bundle directory for deployment.

Automatic jar/war file Resolution

The "jDeploy/jar" and "jDeploy/war" properties specify the location of the jar or war file that constitutes the application. jdeploy init will scan the current directory for eligible jar, war, and web app directories and set the shallowest candidate in the "jDeploy/jar" or "jDeploy/war" directive of the package.json. If you delete this value, or you omit it from the package.json, jdeploy install and jdeploy publish will perform the same search for an appropriate candidate.

Examples

{
  "bin": {"hellojdeploy": "jdeploy-bundle/jdeploy.js"}, (1)
  "preferGlobal": true, (2)
  "version": "1.0.1",
  "jdeploy": {"jar": "dist/HelloJDeploy.jar"}, (3)
  "dependencies": {"shelljs": "^0.7.5"},
  "license": "ISC",
  "name": "hello-jdeploy", (4)
  "files": ["jdeploy-bundle"] (5)
}
  1. Once installed, the binary name of our app will be "hellojdeploy". I.e. we would start the app by typing "hellojdeploy" at the command prompt.

  2. Indicates that NPM should prefer to install the app globally. If people forget to include the "-g" flag when they try to install the app, they will get a warning.

  3. The executable Jar file that we are deploying is located at "dist/HelloJDeploy.jar".

  4. The command to install the app would be npm install -g jdeploy-bundle

The above package.json deploys an app such that it would be installed with

npm install -g hello-jdeploy

And it would be installed as "hellojdeploy", so that it could be run on the command line:

hellojdeploy