我是bazel的新手,有这个演示项目:
(1)mkdir演示项目
(2)cd演示项目
(3)mkdir -p src / main / java / com / demo
(4)vi src / main / java / com / demo / DemoRunner.java
package com.demo;
public class DemoRunner {
public static void main(String args[]) {
Hello.hello();
}
}
(5)vi src / main / java / com / demo / Hello.java
package com.demo;
public class Hello {
public static void hello() {
System.out.println("hello,world");
}
}
(6)vi〜/ demo-project / BUILD
java_binary(
name = "hello",
srcs = glob(["**/*.java"]),
main_class = "com.demo.DemoRunner",
)
(7)bazel build //:您好
Starting local Bazel server and connecting to it...
...........
Analyzing: target //:hello (2 packages loaded)
INFO: Analysed target //:hello (15 packages loaded).
INFO: Found 1 target...
Target //:hello up-to-date:
bazel-bin/hello.jar
bazel-bin/hello
INFO: Elapsed time: 60.505s, Critical Path: 1.24s
INFO: 1 process: 1 worker.
INFO: Build completed successfully, 6 total actions
一切似乎都不错,但是当我尝试
java bazel-bin/hello # Cannot find or load main class bazel-bin.hello
java -jar bazel-bin/hello.jar # Cannot find main list property in bazel-bin/hello.jar
如上所述,两个命令均未成功。那么在bazel编译之后,如何运行Java可执行文件?
非常感谢。
答案 0 :(得分:0)
Bazel命令run
可用于运行指定目标(另请参见Bhavik的注释):
bazel run //:hello