These build rules are used for building Java AppEngine application with Bazel. It does not aim at general WebApplication support but can be easily modified to handle a standard WebApplication.
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.
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:
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:
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.
Another target //hello_app:myapp.deploy allows you to deploy your application to AppEngine. It takes an optional argument: the APP_ID. If not specified, it uses the default APP_ID provided in the application. This target needs to be authorized to AppEngine. Since Bazel does not connect the standard input, it is easier to run it by:
bazel-bin/hello_app/myapp.deploy APP_ID
After the first launch, subsequent launch will be registered to AppEngine so you can just do a normal bazel run //hello_app:myapp.deploy APP_ID to deploy next versions of your application.
appengine_warappengine_war(name, jars, data, data_path)
java_war(name, data, data_path, **kwargs)