我在将 bazel-remote-worker 打包到可部署的 jar 中时遇到问题。
我运行了以下命令:
bazel build //src/tools/remote_worker:remote_worker_deploy.jar
但是当我尝试运行jar时,出现此错误:
➜ bazel git:(master) ✗ java -jar remote_worker_deploy.jar --work_path=/tmp/test --listen_port=3030
*** Initializing in-memory cache server.
*** Not using remote cache. This should be used for testing only!
Exception in thread "main" java.lang.UnsatisfiedLinkError: no unix in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at com.google.devtools.build.lib.UnixJniLoader.loadJni(UnixJniLoader.java:28)
at com.google.devtools.build.lib.unix.NativePosixFiles.<clinit>(NativePosixFiles.java:136)
at com.google.devtools.build.lib.unix.UnixFileSystem.createDirectory(UnixFileSystem.java:309)
at com.google.devtools.build.lib.vfs.Path.createDirectory(Path.java:829)
at com.google.devtools.build.lib.vfs.FileSystemUtils.createDirectoryAndParentsWithCache(FileSystemUtils.java:692)
at com.google.devtools.build.lib.vfs.FileSystemUtils.createDirectoryAndParents(FileSystemUtils.java:652)
at com.google.devtools.build.remote.RemoteWorker.<init>(RemoteWorker.java:114)
at com.google.devtools.build.remote.RemoteWorker.main(RemoteWorker.java:621)
我可以启动它的唯一方法是从bazel-bin
运行可执行文件:
bazel-bin/src/tools/remote_worker/remote_worker --work_path=/tmp/test --listen_port=3030
我正在 mac osx sierra 上运行 bazel 最新(目前a3e26835890a543ff84cce90c879f9196ae06348
(。
我用oracle-jdk-1.8.131
或openjdk-1.8.91
尝试过,它的行为是一样的。
最终目标是创建一个运行这个罐子的 docker 映像,但即使在openjdk:8
这个罐子里的行为也是一样的......
我们没有将本机代码打包到部署 jar 中。实际上,我更愿意重构 RemoteWorker 以避免 Bazel 的大部分内部库,尽管这不太可能很快发生。您可以将 libunix.so 与部署 jar 一起交付,并相应地设置 java.library.path。或者,您可以在构建远程工作程序(bazel-bin/src/tools/remote_worker/remote_worker.runfiles/(后获取整个运行文件树。
自从提出这个问题以来,Bazel 源代码树中的路径发生了变化。如今,获取_deploy.jar的构建命令如下。
bazel build src/tools/remote:worker_deploy.jar
mkdir -p /tmp/cas /tmp/cache /tmp/work
java -jar bazel-bin/src/tools/remote/worker_deploy.jar
--cas_path /tmp/cas --disk_cache /tmp/cache --work_path /tmp/work
bazel build --spawn_strategy=remote
--remote_cache=grpc://${IP}:8080 --remote_executor=grpc://${IP}:8080