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

1.9k views Asked by At

I am doing the clojure cli tutorial from the official clojure site https://clojure.org/guides/deps_and_cli, but I come across this message when I want to run the following: $ 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

I suppose that the command must be executed in the root folder, but just in case I also did it inside src.

The .edn error file is the following:

 "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 version: Clojure 1.10.1

It frustrates me not being able to do something so simple.

--EDIT: I ran 'clojure -Sdescribe' and the version was 1.10.1.492 so I installed the lastest version as Alex said and it goes right, but then I ran again 'describe' and the version didn't change.

I got this:

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 ""}
3

There are 3 answers

2
Alex Miller On BEST ANSWER

The -X functionality was added in the latest version of the Clojure tools (1.10.1.697). From the error message, it looks to me like this is an older version. Can you check with clojure -Sdescribe what version you have?

You can find installation instructions and link to the latest at https://github.com/clojure/tools.deps.alpha/wiki/clj-on-Windows

1
Alan Thompson On

Possibly an easier way to run Clojure on Windows

I cannot stand the Powershell or older CMD.EXE tool. It is, IMHO, much easier to run in bash using Git for Windows.

Steps:

  1. Install JDK 14 from the Oracle site.
  2. Install GitForWindows
  3. Clone the clj-template repo using the GitBash window. Please note that Windows doesn't always start you off in your home directory. You may need something like
    > cd         # go to home dir
    > git clone https://github.com/io-tupelo/clj-template
    > cd clj-template
  1. Install lein from its homepage. Copy the bash script and put it in the $HOME/bin directory:
    > 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....

Don't forget the bare cd when you need to return to the home dir. Also, if you install Java or something, kill the GitBash window and start a new one.


Final result:

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)
$
1
Sean Corfield On

Looking at the output of -Sdescribe, it looks like your previous installation of the Clojure CLI went into your user modules, but you told the new install to go into the system modules:

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"]

You chose 2 from the menu but clojure -Sdescribe shows it is in location 1.

Try to re-run the install script and select install location: 1