尝试通过 Java 子进程运行 swiftlint 失败(通过命令行正常工作)

发布于 2025-01-19 16:19:21 字数 706 浏览 2 评论 0原文

我有一个Java程序来运行不同种类的衬里,使用ProcessBuilder将衬里称为过程。到目前为止,其他Linter的工作大部分都在工作,但是在Swiftlint中,

当我正常从命令行运行时,

swiftlint --enable-all-rules

我正面临一个奇怪的问题,它可以很好地工作,但是通过我的Java子过程实用程序执行相同的问题,

ProcessBuilder processBuilder = new ProcessBuilder("swfitlint", "--enable-all-rules");
Process process = processBuilder.start();

它会失败。 乍一看,以下错误消息

SourceKittenFramework/library_wrapper.swift:31: Fatal error: Loading libsourcekitdInProc.so failed

似乎是由于某些原因,Java程序某些库在通过bash启动命令时可用,而只是为了 当然,我尝试通过我的子过程utif运行以下命令

swiftlint --version

swift --version

,这意味着Java确实可以访问我的机器上安装的Swift二进制文件。任何帮助将不胜感激。

I have a java program to run different kinds of linters, calling the linters as a process using ProcessBuilder. So far, other linters have worked for the most part but with swiftlint, i'm facing a strange issue

When I run it normally from the command line, with

swiftlint --enable-all-rules

It works perfectly, but executing the same through my Java subprocess utility

ProcessBuilder processBuilder = new ProcessBuilder("swfitlint", "--enable-all-rules");
Process process = processBuilder.start();

It fails with the following error message

SourceKittenFramework/library_wrapper.swift:31: Fatal error: Loading libsourcekitdInProc.so failed

At first glance it seems like for some reason certain libraries are not available to the java program which are available to when firing a command through bash, but just to be
sure, I tried running the following command through my subprocess util

swiftlint --version

swift --version

Both of which worked, meaning Java does have access to swift binaries installed on my machine. Any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放血 2025-01-26 16:19:21

我仍然不完全确定为什么会发生这种情况,但我相信这是由于我的机器本身的某种环境问题造成的。
我尝试在 docker 容器内运行相同的代码,该容器使用从以下基本映像构建的映像

FROM openjdk:17-slim as java_base
FROM ghcr.io/realm/swiftlint:latest 
COPY --from=java_base /usr/local/openjdk-17 /usr/local/openjdk-17

,并且它刚刚工作

I'm not still not entirely sure why this happens but i believe it's due to some kind of environment issue on my machine itself.
I tried running the same code inside of a docker container that uses the image built from the following base images

FROM openjdk:17-slim as java_base
FROM ghcr.io/realm/swiftlint:latest 
COPY --from=java_base /usr/local/openjdk-17 /usr/local/openjdk-17

and it just worked

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文