Using bazel to build java war but got error

740 views
Skip to first unread message

ua...@hotmail.com

unread,
Feb 1, 2016, 2:02:33 AM2/1/16
to bazel-discuss
Hi all:

I want to use bazel to build java web applications, but when I run bazel build myproj,it shows such error:

$bazel build //myproj
ERROR: /Users/axb-mac/dev/java/workwpace/myproj/BUILD:3:1: every rule of type appengine_war implicitly depends upon the target '@appengine-java//:api', but this target could not be found. If this is an integration test, maybe you forgot to add a mock for your new tool?
ERROR: Loading failed; build aborted.
INFO: Elapsed time: 0.073s

Here's some more information:

$tree ~/dev/java/workwpace
.
├── WORKSPACE
└── myproj
├── BUILD
├── src
│   └── TestServlet.java
└── webapp
└── web.xml

$cat WORKSPACE
load("/tools/build_rules/appengine/appengine", "appengine_repositories")

appengine_repositories()

$cat myproj/BUILD
load("/tools/build_rules/appengine/appengine", "java_war")

java_war(
name = "myproj",
srcs = ["src/TestServlet.java"],
data = glob(["webapp/**"]),
data_path = "webapp",
deps = [
"//external:appengine/java/api",
"//external:javax/servlet/api",
],
)

$bazel version
Build label: 0.1.4
Build target: bazel-out/local_darwin-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Thu Jan 21 12:53:53 2016 (1453380833)
Build timestamp: 1453380833
Build timestamp as int: 1453380833

$java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

OS X version:El Capitan 10.11.3

I just followed the document at:http://bazel.io/docs/be/appengine.html

I'm not sure if this is the right way to build a 'war' for the tomcat container. Do I miss something?

thanks.

Kristina Chodorow

unread,
Feb 1, 2016, 2:39:16 PM2/1/16
to ua...@hotmail.com, bazel-discuss
You will need to create a tools/build_rules/appengine directory in your workspace and copy /usr/local/lib/bazel/base_workspace/tools/build_rules/appengine/appengine.BUILD into it, i.e.,

$ mkdir -p tools/build_rules/appengine
$ cp /usr/local/lib/bazel/base_workspace/tools/build_rules/appengine/appengine.BUILD tools/build_rules/appengine
$ bazel build //myproj

This has changed since the documentation was written and the error message you're getting isn't helpful (it isn't explain what the actual problem is).  I've filed https://github.com/bazelbuild/bazel/issues/833 for the error message and I'll update the documentation.

(Also, this is a temporary wart: we are working on a change to obviate the need for making the dummy tools/build_rules/appengine directory.)



--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/aceb97bf-e4cb-4c10-b26f-0f45350dadc9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ua...@hotmail.com

unread,
Feb 4, 2016, 1:00:41 AM2/4/16
to bazel-discuss, ua...@hotmail.com
Thanks for your help, "bazel run" reports no error.

But the output war was not same as a normal war package(like a 'war' package in maven)

I found some instructions here: http://bazel.io/docs/be/appengine.html

"These build rules are used for building Java App Engine application with Bazel. It does not aim at general Java web application support but can be easily modified to handle a standard web application."

But I don't know how to modify it...

在 2016年2月2日星期二 UTC+8上午3:39:16,Kristina Chodorow写道:

Damien Martin-guillerez

unread,
Feb 4, 2016, 3:27:00 AM2/4/16
to ua...@hotmail.com, bazel-discuss
You probably want to modify this file: https://github.com/bazelbuild/bazel/blob/master/tools/build_rules/appengine/appengine.bzl#L183
and include the good dependencies. It has been a long time I haven't played with war files so I don't remember how much WEB-INF is different with Java AppEngine WAR ones, maybe you will have some more tweaking to do about that.

gggg...@quinteiro.org

unread,
Feb 13, 2016, 8:19:56 PM2/13/16
to bazel-discuss, ua...@hotmail.com
On Wednesday, February 3, 2016 at 10:00:41 PM UTC-8, ua...@hotmail.com wrote:
> Thanks for your help, "bazel run" reports no error.
>
>
> But the output war was not same as a normal war package(like a 'war' package in maven)
>
>
> I found some instructions here: http://bazel.io/docs/be/appengine.html
>
>
> "These build rules are used for building Java App Engine application with Bazel. It does not aim at general Java web application support but can be easily modified to handle a standard web application."
>
>
> But I don't know how to modify it...
>
Not sure this will help you, but I created a super-simple WAR file rule by butchering the AppEngine rule here: https://github.com/Jose123456/bazel-test/blob/lombok/rules/war.bzl

ua...@hotmail.com

unread,
Feb 15, 2016, 2:58:31 AM2/15/16
to bazel-discuss, ua...@hotmail.com, gggg...@quinteiro.org
Thanks, it works!

But I don't know that why bazel not support java war by default?

在 2016年2月14日星期日 UTC+8上午9:19:56,gggg...@quinteiro.org写道:

Damien Martin-guillerez

unread,
Feb 15, 2016, 5:19:05 AM2/15/16
to ua...@hotmail.com, bazel-discuss, gggg...@quinteiro.org
The appengine support was done because we needed AppEngine support for the Bazel's dashboard but never needed classical war.

We would welcome contribution to make it work outside of appengine :)

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages