Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bmuschko/rules_java_war
Bazel rules for generating a Java Web Archive (WAR).
https://github.com/bmuschko/rules_java_war
bazel bazel-rules java javaee
Last synced: 7 days ago
JSON representation
Bazel rules for generating a Java Web Archive (WAR).
- Host: GitHub
- URL: https://github.com/bmuschko/rules_java_war
- Owner: bmuschko
- License: apache-2.0
- Created: 2019-07-02T21:22:43.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-11-22T04:22:55.000Z (almost 3 years ago)
- Last Synced: 2023-03-11T10:16:36.937Z (over 1 year ago)
- Topics: bazel, bazel-rules, java, javaee
- Language: Python
- Size: 23.4 KB
- Stars: 8
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.adoc
- License: LICENSE
Awesome Lists containing this project
README
= Bazel rules for creating a Java Web Archive (WAR) image:https://travis-ci.org/bmuschko/rules_java_war.svg?branch=master["Build Status", link="https://travis-ci.org/bmuschko/rules_java_war"]
== Overview
The rules provide a way for creating a https://docs.oracle.com/javaee/6/tutorial/doc/bnadx.html[Java Web Archive (WAR)]. The project is compatible with the standard https://github.com/bazelbuild/rules_java[rules_java] and https://github.com/bazelbuild/rules_jvm_external[rules_jvm_external].
== Setup
The easiest way to use the rules is by adding the following to your `WORKSPACE` file:
[source,python]
----
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")RULES_JAVA_WAR_TAG = "0.1.0"
http_archive(
name = "io_bazel_rules_java_war",
strip_prefix = "rules_java_war-%s" % RULES_JAVA_WAR_TAG,
url = "https://github.com/bmuschko/rules_java_war/archive/%s.tar.gz" % RULES_JAVA_WAR_TAG,
sha256 = "38011f979713c4aefd43ab56675ce4c6c14bc949b128c3a303f1f57ebe4bfeac",
)
----== Basic Example
Suppose you are following the typical directory structure for a Java web application:
----
.
├── BUILD
├── WORKSPACE
└── src
└── main
├── java
│ └── com
│ └── bmuschko
│ └── web
│ └── SimpleServlet.java
└── webapp
├── WEB-INF
│ └── web.xml
├── css
│ └── style.css
├── index.html
└── js
└── dynamic.js
----To build the WAR file for the application, a `BUILD` on the root level could look as follows:
[source,python]
----
load("@io_bazel_rules_java_war//java_war:defs.bzl", "java_war")java_war(
name = "web-app",
java_srcs = glob(["src/main/java/**/*.java"]),
deps = [
"@maven//:org_mortbay_jetty_servlet_api",
"@maven//:ch_qos_logback_logback_classic",
],
)
----Under the hood, the macro named `java_war` will generate the `java_library` of the application and then include it as dependency for the WAR file.
[source,bash]
----
$ bazel build //:web-app
INFO: Analyzed target //:web-app (17 packages loaded, 531 targets configured).
INFO: Found 1 target...
Target //:web-app up-to-date:
bazel-bin/web-app.war
INFO: Elapsed time: 7.440s, Critical Path: 5.30s
INFO: 4 processes: 3 darwin-sandbox, 1 worker.
INFO: Build completed successfully, 5 total actions
----The result WAR file contains the content shown below. The rule will include the transitive closure of runtime dependencies. The dependency `org_mortbay_jetty_servlet_api` was declared as "compile-only" dependency and therefore isn't included.
[source,bash]
----
$ cd bazel-bin
$ jar -tf web-app.war
WEB-INF/web.xml
css/style.css
index.html
js/dynamic.js
WEB-INF/lib/liblibextdeps.jar
WEB-INF/lib/logback-classic-1.1.2.jar
WEB-INF/lib/slf4j-api-1.7.6.jar
WEB-INF/lib/logback-core-1.1.2.jar
----== API
=== war
++++
war(name, compression, deps, web_app_root, web_app_srcs)
++++Rule for generating a Java Web Archive (WAR).
==== Attributes
++++
name
Name; required
A unique name for this target.
compression
Boolean; required
Enables compression for the WAR file.
deps
List of labels; optional
Dependencies for this target.
web_app_root
String; required
Root directory containing web application files (e.g. web.xml, CSS or JavaScript files).
web_app_srcs
List of labels; required
Source files to be included fromt the web application root directory.
++++
=== java_war
++++
java_war(name, web_app_dir, java_srcs, deps, compression, kwargs)
++++Creates a Java Web Archive (WAR).
Automatically creates a Java library and bundles it with the web application files and any dependencies.
For more information on the internal structure of a WAR file, see the https://docs.oracle.com/javaee/6/tutorial/doc/bnadx.html[official documentation].==== Parameters
++++
name
required.
A unique name for this rule.
web_app_dir
optional. default is"src/main/webapp"
The root web application directory.
java_srcs
optional. default is[]
Java source files for compilation.
deps
optional. default is[]
Dependencies for this java_library target.
compression
optional. default isFalse
Enables compression for the WAR.
kwargs
optional.
++++