# Java AppEngine Rules for Bazel ## Overview These build rules are used for building [Java AppEngine](https://cloud.google.com/appengine/docs/java/) application with Bazel. It does not aim at general WebApplication support but can be easily modified to handle a standard WebApplication. * [Setup](#setup) * [Basic Example](#basic-example) * [Build Rule Reference](#reference) * [`appengine_war`](#appengine_war) * [`java_war`](#java_war) ## Setup To be able to use the Java AppEngine rules, you must make the AppEngine SDK available to Bazel. The easiest way to do so is by copying the content of `appengine.WORKSPACE` to your workspace file. ## Basic Example Suppose you have the following directory structure for a simple AppEngine application: ``` [workspace]/ WORKSPACE hello_app/ BUILD java/my/webapp/ TestServlet.java webapp/ index.html webapp/WEB-INF web.xml appengine-web.xml ``` Then, to build your webapp, your `hello_app/BUILD` can look like: ```python load("/tools/build_rules/appengine/appengine", "appengine_war") java_library( name = "mylib", srcs = ["java/my/webapp/TestServlet.java"], deps = [ "//external:appengine/java/api", "//external:javax/servlet/api", ], ) appengine_war( name = "myapp", jars = [":mylib"], data = glob(["webapp/**"]), data_path = "webapp", ) ``` For simplicity, you can use the `java_war` rule to build an app from source. Your `hello_app/BUILD` file would then look like: ```python load("/tools/build_rules/appengine/appengine", "java_war") java_war( name = "myapp", srcs = ["java/my/webapp/TestServlet.java"], data = glob(["webapp/**"]), data_path = "webapp", deps = [ "//external:appengine/java/api", "//external:javax/servlet/api", ], ) ``` You can then build the application with `bazel build //hello_app:myapp` and run in it a development server with `bazel run //hello_app:myapp`. This will bind a test server on port 8080. If you wish to select another port, simply append the `--port=12345` to the command-line. ## Build Rule Reference [reference] ### `appengine_war` `appengine_war(name, jars, data, data_path)`
Attribute Description
name Name, required

A unique name for this rule.

jars List of labels, required

List of JAR files that will be uncompressed as the code for the Web Application.

If it is a `java_library` or a `java_import`, the JAR from the runtime classpath will be added in the `lib` directory of the Web Application.

data List of files, optional

List of files used by the Web Application at runtime.

This attribute can be used to specify the list of resources to be included into the WAR file.

data_path String, optional

Root path of the data.

The directory structure from the data is preserved inside the WebApplication but a prefix path determined by `data_path` is removed from the the directory structure. This path can be absolute from the workspace root if starting with a `/` or relative to the rule's directory. It is set to `.` by default.

### `java_war` `java_war(name, data, data_path, **kwargs)`
Attribute Description
name Name, required

A unique name for this rule.

data List of labels, optional

List of files used by the Web Application at runtime.

Passed to the appengine_war rule.

data_path String, optional

Root path of the data.

Passed to the appengine_war rule.

**kwargs see java_library

The other arguments of this rule will be passed to build a `java_library` that will be passed in the `jar` arguments of a appengine_war rule.