Clojurescript: Error: Could not find or load main class clojure.main - clojurescript

I installed Clojurescript following its quick start guide.
I pulled the git repo to ~/clojurescript.
CLOJURESCRIPT_HOME is set ~/clojurescript and clojurescript/bin is added to system path.
When I try to use commands cljsc I get following error
Could not find or load main class clojure.main
How can I solve it?

Alright coming back after 5 years.
This error surfaces when one runs clj --main cljs.main --compile hello-world.core --repl from directory or path which does not have file deps.edn or cljs.jar.
Considering the directory structure at https://clojurescript.org/guides/quick-start,
hello-world #### Run that command in this directory
├─ src
│ └─ hello_world
│ └─ core.cljs
├─ cljs.jar
└─ deps.edn
i.e.
$ cd hello-world
$ clj --main cljs.main --compile hello-world.core --repl

I was going through this tutorial today.
I checked here for this error. The version of the standalone jar was correct. The problem was caused by a 'typing mistake' in the core.cljs file. The string "Hello world!" was not in double quotes. Initially the string was in single quotes and included a comma.
The other issue I struggled with was getting the java command to work. I was using a Cygwin64 Terminal.
The correct command for the Cygwin64 Terminal is:
$ java -cp "cljs.jar;src" clojure.main build.clj

In my case, I was typing Windows command by mistake which has " in the command + make sure you'll have the cljs.jar in your root folder bes
java -cp cljs.jar:src clojure.main build.clj
I hope it helps someone, one day.:)

If you have created your project using leiningen then your project cli would look something like this
(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"]]
)
After the :dependencies add the following lines
:jar-name "<project-name>.jar"
:jar-path "/target/<project-name>.jar"
Note : you need the replace the project name with your project
After that run the following command
lein jar

Ensure that the JAR file at classpath exists:
java -cp target/missing-file.jar clojure.main your.namespace
will confusingly throw Could not find or load main class clojure.main.

Related

How do I fix this error in with deps.edn file?

I have created a project called tutorial with a deps.edn file in it. I also have a core.cljs file in tutorial/src/appy.
When I run the command clj -m cljs.main --compile appy.core --repl following a tutorial I get an error.
Error building classpath. Error reading edn. Map literal must contain an even number of forms (C:\Users\...\tutorial\deps.edn)
The content of the deps.edn file is
{:deps {org.clojure/clojurescript {:mvn/version "1.10.773"}}
:paths ["src"]}
I understand the error but not why it is generated.

cljs quick start failed to locate namespace

I tries to quick start cljs, but the similar problem occurred.
clojure 1.10.3 on linux openjdk 17.0.1
project folder:
.
|_ deps.edn
|_ src
|_ helloworld
|_ core.cljs
core.cljs:
(ns helloworld.core)
(println "helloworld")
deps.edn
{:deps {org.clojure/clojurescript {:mvn/version "1.10.758"}}}
tried to quick start under the project folder but failed,
$ clj -M -m cljs.main -c helloworld.core
Unexpected error (IllegalArgumentException) compiling at (REPL:1).
Namespace helloworld.core does not exist.
#EDIT However, tried on lein-cljsbuild successfully.
$ lein cljsbuild once
project.clj (instead of deps.edn):
(defproject helloworld "0.1.0"
:dependencies [[org.clojure/clojure "1.10.3"]
[org.clojure/clojurescript "1.10.758"]]
:plugins [[lein-cljsbuild "1.1.8"]]
:cljsbuild {:builds [{:source-paths ["src"]}]})
#EDIT I had to reboot the machine then tried again by chance - it works now. but "why" remains mysterious.
In the tutorial, it wants src/hello_world/core.cljs as the file and hello-world.core for the namespace but you have helloworld.core for the ns and say you have src/helloworld/core.cljs for the file (which ought to work). That's the only difference I can see from the tutorial.
In addition, the tutorial has --repl on the clj command to cause a (ClojureScript) REPL to be started after compiling helloworld.core (using your ns).
That all works as expected for me:
(! 600)-> tree .
.
|____deps.edn
|____src
| |____helloworld
| | |____core.cljs
(! 601)-> cat deps.edn
{:deps {org.clojure/clojurescript {:mvn/version "1.10.758"}}}
(! 602)-> cat src/helloworld/core.cljs
(ns helloworld.core)
(println "helloworld")
(! 603)-> clj -M -m cljs.main -c helloworld.core -r
ClojureScript 1.10.758
cljs.user=> helloworld
(and a browser opens with the ClojureScript welcome page)
That was with Clojure CLI 1.10.3.1029 (the latest) but I also tested it with 1.10.1.561 to make sure recent changes haven't affected the behavior and it also worked as expected.
I would recommend checking that you have the correct Clojure CLI installed:
(! 605)-> clj -version
Clojure CLI version 1.10.3.1029
(! 606)-> clj -Sdescribe
{:version "1.10.3.1029"
:config-files ["/usr/local/Cellar/clojure#1.10.3.1029/1.10.3.1029/deps.edn" "/Users/sean/.clojure/deps.edn" "deps.edn" ]
:config-user "/Users/sean/.clojure/deps.edn"
:config-project "deps.edn"
:install-dir "/usr/local/Cellar/clojure#1.10.3.1029/1.10.3.1029"
:config-dir "/Users/sean/.clojure"
:cache-dir ".cpcache"
:force false
:repro false
:main-aliases ""
:repl-aliases ""}
(the installation instructions are here: https://clojure.org/guides/getting_started if have some rogue clj script instead of the official one)
I suspect you have a non-standard clj script installed that tried to just run helloworld.core as if it were a .clj file.

ClojureScript - How to load user.cljs file for repl sessions

I'm starting a cljs repl with a node.js environment.
=> clj -m cljs.main -re node
Documentation for using the repl says that you can place a user.cljs file at the classpath root for the project and it will be automatically loaded into a repl session in the cljs.user namespace.
I have a src directory with user.cljs at its base. The project's directory structure looks like the following.
xyz / deps.edn
/ src / xyz / core.cljs
/ user.cljs
ClojureScript version 1.10.520 is the only dependency in deps.edn.
Whenever I start the repl I get the following error.
Execution error (IllegalArgumentException) at cljs.closure/compile-file (closure.clj:639).
/var/folders/rk/r65ng3n93l53h95nsvkl265c0000gn/T/out385499094487053918164582825852/cljs/user/user5D28A44.js is not a relative path
When I look in the temporary output folder it is clear that ../cljs/user/user5D28A44.js is not being generated.
Is this a cljs bug? Can someone show me an example of this working correctly?
You have to start the ClojureScript repl explicitly from clojure programmatically, the command line startup short hand doesn't work for loading user.cljs.
=> clj
Clojure 1.10.1
user=> (require '[cljs.repl :as repl])
user=> (require '[cljs.repl.node :as node])
user=> (def env (node/repl-env))
user=> (repl/repl env)
cljs.user=> working?
"Yes."
cljs.user=> ...
With the working? symbol defined in user.cljs it is available as you would expect.
It’s a known issue. See: CLJS-2917
You can work around it by specifying an output directory via -d.

warbling a simple ruby sample with YAML dependency

I try to make a .JAR from a simple ruby sample. In MRI and jRuby i can run this without problem but when i try to warble the project i get error when i run the JAR file.
Errno::ENOENT: No such file or directory - configuration.yml
The configuration.yml file is not in the project folder because is needs to be editable so shouldn't be in the JAR included, optimally the path would be relative to the jar so that the YML file is in the same folder as the JAR file. So how could i do this ?
My bin\sample.rb
require 'yaml'
#conf = YAML::load_file "c:/test/configuration.yml"
##conf = YAML::load_file "c:\\test\\configuration.yml"
puts #conf['username']
My c:\test\configuration.yml
username: test
My .gemspec file
Gem::Specification.new do |spec|
spec.require_paths << '.'
}
My config\warble.rb
Warbler::Config.new do |config|
config.jar_name = "sample"
end
I warble with "warble jar -trace" and get no errors
I use jruby-1.7.4 and warbler-1.3.8.
Figured it out without using java as some solutions on the web suggest (but not for warble).
require 'yaml'
scriptpath = __FILE__[/(.*)\/.+\.jar!/]
yamlpath = "#{$1[6..-1]}/configuration.yml"
#conf = YAML::load_file(yamlpath)
puts #conf['username']
# => test

Need help with perl error in using DBD::mysql

When I run a perl script which uses DBD::mysql , I get the error message:
install_driver(mysql) failed: Can't load '/home/y/lib/perl5/site_perl/5.8/i686-linux-64int/auto/DBD/mysql/mysql.so'
for module DBD::mysql: libmysqlclient.so.16: cannot open shared object file: No such file or directory
at /home/y/lib/perl5/5.8/i686-linux-64int/DynaLoader.pm line 230. at (eval 30) line 3
I am new to perl, but from what I understand it needs mysql.so and it knows the path.
/home/y/lib/perl5/site_perl/5.8/i686-linux-64int/auto/DBD/mysql/mysql.so is present.
Then why the problem?
The file that is missing is libmysqlclient.so.16, not mysql.so. It comes with the mysqlclient package on some distributions.
Make sure /etc/ld.so.conf contains /usr/local/mysql/lib/mysql and /usr/local/mysql/ . If not, add them and run ldconfig.