当我尝试运行“exec”时在SBT中,我得到“运行 exec 时出错:java.lang.ArrayIndexOutOfBoundsException:0”。如何修复?

发布于 2024-09-26 06:27:56 字数 2425 浏览 4 评论 0原文

如果我创建一个 SBT 项目,即使是一个简单的“hello world”,编译(成功)然后执行,则会引发以下错误。原因可能是什么以及如何解决这个问题?


java.lang.ArrayIndexOutOfBoundsException: 0
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
    at sbt.SimpleProcessBuilder.run(ProcessImpl.scala:381)
    at sbt.AbstractProcessBuilder.run(ProcessImpl.scala:130)
    at sbt.AbstractProcessBuilder.$bang(ProcessImpl.scala:158)
    at sbt.ExecProject$$anonfun$execOut$1.apply(ScalaProject.scala:436)
    at sbt.ExecProject$$anonfun$execOut$1.apply(ScalaProject.scala:435)
    at sbt.TaskManager$Task.invoke(TaskManager.scala:62)
    at sbt.impl.RunTask.doRun$1(RunTask.scala:77)
    at sbt.impl.RunTask.runTask(RunTask.scala:85)
    at sbt.impl.RunTask.run(RunTask.scala:32)
    at sbt.impl.RunTask$.apply(RunTask.scala:17)
    at sbt.impl.RunTask$.apply(RunTask.scala:16)
    at sbt.Project$class.run(Project.scala:98)
    at sbt.Project$class.call(Project.scala:93)
    at sbt.BasicScalaProject.call(DefaultProject.scala:21)
    at sbt.xMain$$anonfun$7.apply(Main.scala:512)
    at sbt.xMain$$anonfun$7.apply(Main.scala:512)
    at sbt.xMain.withAction(Main.scala:541)
    at sbt.xMain.sbt$xMain$$handleAction(Main.scala:512)
    at sbt.xMain.handleCommand(Main.scala:502)
    at sbt.xMain.processAction(Main.scala:441)
    at sbt.xMain.process$1(Main.scala:257)
    at sbt.xMain$Continue$1.apply(Main.scala:132)
    at sbt.xMain.run$1(Main.scala:136)
    at sbt.xMain.processArguments(Main.scala:266)
    at sbt.xMain.startProject(Main.scala:107)
    at sbt.xMain.run(Main.scala:84)
    at sbt.xMain.run0$1(Main.scala:35)
    at sbt.xMain.run(Main.scala:42)
    at xsbt.boot.Launch$.run(Launch.scala:53)
    at xsbt.boot.Launch$$anonfun$explicit$1.apply(Launch.scala:42)
    at xsbt.boot.Launch$$anonfun$explicit$1.apply(Launch.scala:42)
    at xsbt.boot.Launch$.launch(Launch.scala:57)
    at xsbt.boot.Launch$.explicit(Launch.scala:42)
    at xsbt.boot.Launch$.initialized(Launch.scala:38)
    at xsbt.boot.Launch$.parsed(Launch.scala:31)
    at xsbt.boot.Launch$.configured(Launch.scala:21)
    at xsbt.boot.Launch$.apply(Launch.scala:16)
    at xsbt.boot.Launch$.apply(Launch.scala:13)
    at xsbt.boot.Boot$.runImpl(Boot.scala:24)
    at xsbt.boot.Boot$.run(Boot.scala:19)
    at xsbt.boot.Boot$.main(Boot.scala:15)
    at xsbt.boot.Boot.main(Boot.scala)
[info] == exec ==
[error] Error running exec: java.lang.ArrayIndexOutOfBoundsException: 0

If I create an SBT project, even a simple "hello world", compile (successfully) and then exec, the folowing error is thrown. WHat may the reason be and how to fix this?


java.lang.ArrayIndexOutOfBoundsException: 0
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
    at sbt.SimpleProcessBuilder.run(ProcessImpl.scala:381)
    at sbt.AbstractProcessBuilder.run(ProcessImpl.scala:130)
    at sbt.AbstractProcessBuilder.$bang(ProcessImpl.scala:158)
    at sbt.ExecProject$anonfun$execOut$1.apply(ScalaProject.scala:436)
    at sbt.ExecProject$anonfun$execOut$1.apply(ScalaProject.scala:435)
    at sbt.TaskManager$Task.invoke(TaskManager.scala:62)
    at sbt.impl.RunTask.doRun$1(RunTask.scala:77)
    at sbt.impl.RunTask.runTask(RunTask.scala:85)
    at sbt.impl.RunTask.run(RunTask.scala:32)
    at sbt.impl.RunTask$.apply(RunTask.scala:17)
    at sbt.impl.RunTask$.apply(RunTask.scala:16)
    at sbt.Project$class.run(Project.scala:98)
    at sbt.Project$class.call(Project.scala:93)
    at sbt.BasicScalaProject.call(DefaultProject.scala:21)
    at sbt.xMain$anonfun$7.apply(Main.scala:512)
    at sbt.xMain$anonfun$7.apply(Main.scala:512)
    at sbt.xMain.withAction(Main.scala:541)
    at sbt.xMain.sbt$xMain$handleAction(Main.scala:512)
    at sbt.xMain.handleCommand(Main.scala:502)
    at sbt.xMain.processAction(Main.scala:441)
    at sbt.xMain.process$1(Main.scala:257)
    at sbt.xMain$Continue$1.apply(Main.scala:132)
    at sbt.xMain.run$1(Main.scala:136)
    at sbt.xMain.processArguments(Main.scala:266)
    at sbt.xMain.startProject(Main.scala:107)
    at sbt.xMain.run(Main.scala:84)
    at sbt.xMain.run0$1(Main.scala:35)
    at sbt.xMain.run(Main.scala:42)
    at xsbt.boot.Launch$.run(Launch.scala:53)
    at xsbt.boot.Launch$anonfun$explicit$1.apply(Launch.scala:42)
    at xsbt.boot.Launch$anonfun$explicit$1.apply(Launch.scala:42)
    at xsbt.boot.Launch$.launch(Launch.scala:57)
    at xsbt.boot.Launch$.explicit(Launch.scala:42)
    at xsbt.boot.Launch$.initialized(Launch.scala:38)
    at xsbt.boot.Launch$.parsed(Launch.scala:31)
    at xsbt.boot.Launch$.configured(Launch.scala:21)
    at xsbt.boot.Launch$.apply(Launch.scala:16)
    at xsbt.boot.Launch$.apply(Launch.scala:13)
    at xsbt.boot.Boot$.runImpl(Boot.scala:24)
    at xsbt.boot.Boot$.run(Boot.scala:19)
    at xsbt.boot.Boot$.main(Boot.scala:15)
    at xsbt.boot.Boot.main(Boot.scala)
[info] == exec ==
[error] Error running exec: java.lang.ArrayIndexOutOfBoundsException: 0

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

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

发布评论

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

评论(1

灵芸 2024-10-03 06:27:56

构建操作 exec 的目的是在底层 shell 上执行命令。因此,需要遵循命令。 EG:

exec killall firefox

在幕后,SBT 调用 java.lang.ProcessBuilder,如果调用者尝试启动它但未提供任何参数,则会抛出此异常。

IndexOutOfBoundsException - If the command is an empty list (has size 0)

我认为 SBT 不应该传播这个异常,这是一个错误。您应该收到一条错误消息。

也许您正在寻找构建操作run,它将调用您的主类。

The purpose of the build action exec is to execute a command on the underlying shell. As such it needs to be followed with a command. EG:

exec killall firefox

Under the covers, SBT calls java.lang.ProcessBuilder, which throws this Exception if the caller tries to start it but has not provided any parameters.

IndexOutOfBoundsException - If the command is an empty list (has size 0)

I reckon SBT should not be propagating this exception and that this is a bug. You should get an error message instead.

Perhaps you were looking for the build action run, which will invoke your main class.

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