gpt4 book ai didi

java - Bazel 构建 Java 演示 : build ok but fail to run

转载 作者:行者123 更新时间:2023-11-30 12:08:01 24 4
gpt4 key购买 nike

我是 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 构建//:你好

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 可执行文件?

最佳答案

Bazel 命令 run 可用于运行指定的目标(另请参阅 Bhavik 的评论):

bazel run //:hello

关于java - Bazel 构建 Java 演示 : build ok but fail to run,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54526458/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com