bazel build java库不会生成任何类文件

时间:2019-02-05 23:21:14

标签: java class build classpath bazel

我是bazel的新手,我有这个演示项目和BUILD文件:

package com.demo;

public class Hello {
    public static void hello() {
        System.out.println("hello,world");
    }
}

(1)mkdir src / main / java / com / demo,然后我就知道了

DemoRunner.java:

package com.demo;
public class DemoRunner {
    public static void main(String args[]) {
        Hello.hello();
    }
}

Hello.java

package com.demo;

public class Hello {
    public static void hello() {
        System.out.println("hello,world");
    }
}

然后我跑:

bazel build //:hello
bazel build //:HelloTest

它找不到库:

java -classpath bazel-bin/hello.jar com.demo.DemoRunnerException in thread 
"main" java.lang.NoClassDefFoundError: com/demo/Hello
    at com.demo.DemoRunner.main(DemoRunner.java:4)
Caused by: java.lang.ClassNotFoundException: com.demo.Hello
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 1 more

我使用“查找”命令来搜索“ .class”文件,但未找到任何文件。我使用“ jar”文件检查hello.jar,我发现只有“ class DemoRunner类”存在,但缺少“ class Hello”:

jar tvf bazel-bin/hello.jar
  0 Fri Jan 01 00:00:00 CST 2010 META-INF/
 68 Fri Jan 01 00:00:00 CST 2010 META-INF/MANIFEST.MF
  0 Fri Jan 01 00:00:00 CST 2010 com/
  0 Fri Jan 01 00:00:00 CST 2010 com/demo/
466 Fri Jan 01 00:00:02 CST 2010 com/demo/DemoRunner.class

那么我在哪里弄错了,如何构建我的库文件并使其运行?但是,方式是,bazel将javac输出的所有类文件存储在哪里?

0 个答案:

没有答案