我可以从eclipse导出到.war文件并在Tomcat上运行它。但是,当我使用Bazel构建它时,生成的.war文件不会在Tomcat上运行。
项目结构
project
|_src
| |_main/java/*.java
|
|_WebContent
|_META-INF
|_Manifest.mf
|_WEB-INF
|_lib/*.jar
|_web.xml
从eclipse(和工作)导出的War文件如下所示:
inflated: META-INF/MANIFEST.MF
inflated: .DS_Store
created: META-INF/
created: WEB-INF/
created: WEB-INF/classes/
created: WEB-INF/classes/main/
created: WEB-INF/classes/main/java/
inflated: WEB-INF/classes/main/java/.DS_Store
inflated: WEB-INF/classes/main/java/foo.class
inflated: WEB-INF/classes/main/.DS_Store
inflated: WEB-INF/classes/.DS_Store
inflated: WEB-INF/.DS_Store
created: WEB-INF/lib/
inflated: WEB-INF/lib/.DS_Store
inflated: WEB-INF/lib/jersey-bundle-1.19.jar
inflated: WEB-INF/web.xml
当我用Bazel创建.war时,我明白了:
created: ./
created: ./WEB-INF/
created: ./WEB-INF/classes/
created: ./WEB-INF/classes/main/
created: ./WEB-INF/classes/main/java/
inflated: ./WEB-INF/classes/main/java/.DS_Store
inflated: ./WEB-INF/classes/main/java/foo.class
created: ./WEB-INF/lib/
inflated: ./WEB-INF/lib/jersey-bundle-1.19.jar
inflated: ./WEB-INF/web.xml
我正在使用以下代码自定义.bzl文件以获取war文件:
def _war_impl(ctxt):
zipper = ctxt.file._zipper
data_path = ctxt.attr.data_path
war = ctxt.outputs.war
build_output = war.path + ".WEB-INF"
print("build_output = %s" % (build_output))
cmd = [
"set -e;rm -rf " + build_output,
"mkdir -p %s" % build_output
]
inputs = ctxt.files.jars + [zipper]
cmd += ["mkdir -p %s/WEB-INF/lib" % build_output]
cmd += ["mkdir -p %s/WEB-INF/classes/main/java" % build_output]
任何人都可以指出如何使用' mkdir'所以它没有创造' ./' war文件中的目录?
答案 0 :(得分:1)
原来问题在于Bazel文件(我创建了类似于appengine bazel规则的自定义.bzl规则)用于压缩文件的命令:
def _make_war(zipper, input_dir, output):
return [
"(root=$(pwd);" +
("cd %s &&" % input_dir) +
("${root}/%s Cc ${root}/%s $(find .))" % (zipper.path, output.path))
]
$(find。)正在返回./WEB-INF,所以当我将其更改为$(找到WEB-INF)时,它返回了一个没有' ./'的.war文件;目录,然后在Tomcat上运行。