我按照其快速入门指南安装了 Clojurescript。
我将 git 存储库拉到了
~/clojurescript
。
CLOJURESCRIPT_HOME
设置 ~/clojurescript
并将 clojurescript/bin
添加到系统路径。
当我尝试使用命令时
cljsc
我收到以下错误
Could not find or load main class clojure.main
如何解决?
好吧,5年后回来了。
当从没有文件
clj --main cljs.main --compile hello-world.core --repl
或 deps.edn
的目录或路径运行 cljs.jar
时,会出现此错误。
考虑https://clojurescript.org/guides/quick-start、
的目录结构hello-world #### Run that command in this directory
├─ src
│ └─ hello_world
│ └─ core.cljs
├─ cljs.jar
└─ deps.edn
即
$ cd hello-world
$ clj --main cljs.main --compile hello-world.core --repl
我今天正在学习本教程。
我在这里检查了这个错误。独立 jar 的版本是正确的。该问题是由 core.cljs 文件中的“输入错误”引起的。字符串“Hello world!”不在双引号中。最初,该字符串使用单引号并包含逗号。
我遇到的另一个问题是让 java 命令正常工作。我使用的是 Cygwin64 终端。
Cygwin64 终端的正确命令是:
$ java -cp "cljs.jar;src" clojure.main build.clj
就我而言,我错误地输入了 Windows 命令,命令中有
"
+ 确保您的根文件夹 bes中有
cljs.jar
java -cp cljs.jar:src clojure.main build.clj
我希望有一天它能对某人有所帮助。:)
如果您使用 leiningen 创建了项目,那么您的项目 cli 将如下所示
(defproject clojuredemo "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]]
)
在:依赖项之后添加以下行
:jar-name "<project-name>.jar"
:jar-path "/target/<project-name>.jar"
注意:您需要将项目名称替换为您的项目
之后运行以下命令
lein jar
确保类路径中的 JAR 文件存在:
java -cp target/missing-file.jar clojure.main your.namespace
会令人困惑地抛出
Could not find or load main class clojure.main
。
就我而言,我在尝试运行使用 clojure 构建工具编译的 uberjar 文件后收到此错误。问题是我忘记将
(:gen-class)
键添加到 ns
调用中:
(ns my.namespace
(:require [...])
(:gen-class))