无法使用 clojure cli 工具执行主要功能 'run' - Deps 和 CLI 指南

Can't execute main function 'run' with clojure cli tools - Deps and CLI Guide

我正在从官方 clojure 站点 https://clojure.org/guides/deps_and_cli 学习 clojure cli 教程,但是当我想要 运行 以下内容时遇到此消息:$ clj -X hello/run

Execution error (FileNotFoundException) at java.io.FileInputStream/open0 (FileInputStream.
-X (El sistema no puede encontrar el archivo especificado)

Full report at:
C:\Users\usuario\AppData\Local\Temp\clojure-16611030546441487090.edn

我想该命令必须在根文件夹中执行,但为了以防万一,我也在 src 中执行了。

.edn 错误文件如下:

 "Execution error (FileNotFoundException) at java.io.FileInputStream/open0 (FileInputStream.java:-2).\r\n-X (El sistema no puede encontrar el archivo especificado)\r\n",
 :clojure.main/triage
 {:clojure.error/class java.io.FileNotFoundException,
  :clojure.error/line -2,
  :clojure.error/cause
  "-X (El sistema no puede encontrar el archivo especificado)",
  :clojure.error/symbol java.io.FileInputStream/open0,
  :clojure.error/source "FileInputStream.java",
  :clojure.error/phase :execution},
 :clojure.main/trace
 {:via
  [{:type java.io.FileNotFoundException,
    :message
    "-X (El sistema no puede encontrar el archivo especificado)",
    :at [java.io.FileInputStream open0 "FileInputStream.java" -2]}],
  :trace
  [[java.io.FileInputStream open0 "FileInputStream.java" -2]
   [java.io.FileInputStream open "FileInputStream.java" 219]
   [java.io.FileInputStream <init> "FileInputStream.java" 157]
   [java.io.FileInputStream <init> "FileInputStream.java" 112]
   [clojure.lang.Compiler loadFile "Compiler.java" 7571]
   [clojure.main$load_script invokeStatic "main.clj" 475]
   [clojure.main$script_opt invokeStatic "main.clj" 535]
   [clojure.main$script_opt invoke "main.clj" 530]
   [clojure.main$main invokeStatic "main.clj" 664]
   [clojure.main$main doInvoke "main.clj" 616]
   [clojure.lang.RestFn applyTo "RestFn.java" 137]
   [clojure.lang.Var applyTo "Var.java" 705]
   [clojure.main main "main.java" 40]],
  :cause "-X (El sistema no puede encontrar el archivo especificado)"}}

Clojure 版本:Clojure 1.10.1

我很沮丧不能做这么简单的事情。

——编辑: 我 运行 'clojure -Sdescribe' 并且版本是 1.10.1.492 所以我按照 Alex 的说法安装了最新版本并且一切正常,但是后来我再次 运行 'describe' 并且版本没有'改变。

我知道了:

PS C:\Users\usuario\downloads> .\win-install-1.10.1.697.ps1
Security warning
Run only scripts that you trust. While scripts from the internet can be useful, this
script can potentially harm your computer. If you trust this script, use the Unblock-File
 cmdlet to allow the script to run without this warning message. Do you want to run

C:\Users\usuario\downloads\win-install-1.10.1.697.ps1?
[D] Do not run  [R] Run once  [S] Suspend  [?] Help (default is "D"): R
Downloading Clojure tools
WARNING: Clojure will install as a module in your PowerShell module path.

Possible install locations:
  1) C:\Users\usuario\Documents\WindowsPowerShell\Modules
  2) C:\Program Files\WindowsPowerShell\Modules
  3) C:\Windows\system32\WindowsPowerShell\v1.0\Modules
Enter number of preferred install location: 2

Cleaning up existing install
Installing PowerShell module
Removing download
Clojure now installed. Use "clj -h" for help.

PS C:\Users\usuario\downloads> clojure -Sdescribe
{:version "1.10.1.492"
 :config-files ["C:\Users\usuario\Documents\WindowsPowerShell\Modules\ClojureTools\deps.edn" "C:\Users\usuario\.clojure\
deps.edn" "deps.edn"]
 :config-user "C:\Users\usuario\.clojure\deps.edn"
 :config-project "deps.edn"
 :install-dir "C:\Users\usuario\Documents\WindowsPowerShell\Modules\ClojureTools"
 :config-dir "C:\Users\usuario\.clojure"
 :cache-dir "C:\Users\usuario\.clojure\.cpcache"
 :force False
 :repro False
 :resolve-aliases ""
 :classpath-aliases ""
 :jvm-aliases ""
 :main-aliases ""
 :all-aliases ""}

最新版本的 Clojure 工具 (1.10.1.697) 中添加了 -X 功能。从错误消息来看,在我看来这是一个旧版本。你能检查 clojure -Sdescribe 你有什么版本吗?

您可以在 https://github.com/clojure/tools.deps.alpha/wiki/clj-on-Windows

找到最新的安装说明和 link

可能是在 Windows

上 运行 Clojure 的更简单方法

我受不了 Powershell 或更旧的 CMD.EXE 工具。恕我直言,使用 Git 在 bash 中 运行 对于 Windows[=39= 更容易].

步骤:

  1. 安装JDK14from the Oracle site.
  2. 安装GitForWindows
  3. 使用 GitBash window 克隆 the clj-template repo。请注意 Windows 并不总是在您的主目录中启动。您可能需要
    > cd         # go to home dir
    > git clone https://github.com/io-tupelo/clj-template
    > cd clj-template
  1. 安装leinfrom its homepage。复制bash脚本,放到$HOME/bin目录下:
    > cd            # go to home dire
    > mkdir bin     # make a $HOME/bin dir
    
    <<< In browser, download [this bash script][5] and save it as `bin/lein`
     without any suffix (i.e. not `bin/lein.bash`) >>>
    
    <<< kill the gitbash window and make a new one >>>
    
    > lein --version    # should download lots of jar files
    ....<snip>....
    
    > lein --version    # should just print version info
    Leiningen 2.9.4 on Java 14....

当您需要 return 到主目录时,请不要忘记 cd。 此外,如果你安装 Java 或其他东西,请杀死 GitBash window 并启动一个新的。


最终结果:

thomp@DESKTOP-0FP4EPJ MINGW64 /
$ cd

thomp@DESKTOP-0FP4EPJ MINGW64 ~
$ cd clj-template/

thomp@DESKTOP-0FP4EPJ MINGW64 ~/clj-template (master)
$ lein test
Compiling 1 source files to C:\Users\thomp\clj-template\target\default+test+test\class-files

lein test _bootstrap

-----------------------------------
   Clojure 1.10.1    Java 11.0.8
-----------------------------------

lein test tst.demo.core

Ran 3 tests containing 8 assertions.
0 failures, 0 errors.

thomp@DESKTOP-0FP4EPJ MINGW64 ~/clj-template (master)
$

查看 -Sdescribe 的输出,您之前安装的 Clojure CLI 似乎进入了您的用户模块,但您告诉新安装进入系统模块:

Possible install locations:
  1) C:\Users\usuario\Documents\WindowsPowerShell\Modules
  2) C:\Program Files\WindowsPowerShell\Modules
  3) C:\Windows\system32\WindowsPowerShell\v1.0\Modules
Enter number of preferred install location: 2

Cleaning up existing install
Installing PowerShell module
Removing download
Clojure now installed. Use "clj -h" for help.

PS C:\Users\usuario\downloads> clojure -Sdescribe
{:version "1.10.1.492"
 :config-files ["C:\Users\usuario\Documents\WindowsPowerShell\Modules\ClojureTools\deps.edn" "C:\Users\usuario\.clojure\
deps.edn" "deps.edn"]

您从菜单中选择了 2,但 clojure -Sdescribe 显示它位于 1 位置。

尝试re-run安装脚本和select安装位置:1