FileNotFoundException when requiring namespaces in Clojure - clojure

I want to use clojure.java.io and clojure.data.csv in my app.
This is how I've required those namespaces:
(ns my-app.core
(:gen-class)
(:require [clojure.java.io :as io]
[clojure.data.csv :as csv]))
When I evaluate that ns function in the REPL, I get this error:
; Execution error (FileNotFoundException) at my-app.core/eval8295$loading (form-init1647489175359256060.clj:1).
; Could not locate clojure/data/csv__init.class, clojure/data/csv.clj or clojure/data/csv.cljc on classpath.
VS Code v1.62.3 / Calva. v2.0.229 / Leiningen v2.9.8 on Java v15.0.1 / macOS v11.6.1
This is my Java class path, as produced with within the same REPL session by calling (java.lang.System/getProperty "java.class.path"):
"/Users/my-username/Code/my-app/test:/Users/my-username/Code/my-app/src:/Users/my-username/Code/my-app/dev-resources:/Users/my-username/Code/my-app/resources:/Users/my-username/Code/my-app/target/default/classes:/Users/my-username/.m2/repository/cider/cider-nrepl/0.22.4/cider-nrepl-0.22.4.jar:/Users/my-username/.m2/repository/nrepl/nrepl/0.8.3/nrepl-0.8.3.jar:/Users/my-username/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar:/Users/my-username/.m2/repository/org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.jar:/Users/my-username/.m2/repository/org/clojure/core.specs.alpha/0.2.56/core.specs.alpha-0.2.56.jar:/Users/my-username/.m2/repository/org/nrepl/incomplete/0.1.0/incomplete-0.1.0.jar"
And this is my app directory structure (scaffolded with lein new app my-app):
.
├── CHANGELOG.md
├── LICENSE
├── README.md
├── doc
│   └── intro.md
├── project.clj
├── resources
│   ├── my-data-1.csv
│   └── my-data-2.csv
├── src
│   └── my_app
│   └── core.clj
├── target
│   └── default
│   ├── classes
│   │   └── META-INF
│   │   └── maven
│   │   └── my-app
│   │   └── my-app
│   │   └── pom.properties
│   ├── repl-port
│   └── stale
│   └── leiningen.core.classpath.extract-native-dependencies
└── test
└── my_app
└── core_test.clj
It looks like something is wrong with my Java environment, or perhaps my Clojure installation. I can't seem to figure out where the problem lies, and how to go about fixing it.
Any advice would be greatly appreciated.

I had neglected to add clojure.data.csv to my project.clj file.
Here is the project.clj with the changes applied to :dependencies:
(defproject my-app "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
:url "https://www.eclipse.org/legal/epl-2.0/"}
:dependencies [[org.clojure/clojure "1.10.3"]
[org.clojure/data.csv "1.0.0"]]
:main ^:skip-aot my-app.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all
:jvm-opts ["-Dclojure.compiler.direct-linking=true"]}})
Relevant part:
:dependencies [[org.clojure/clojure "1.10.3"]
[org.clojure/data.csv "1.0.0"]]
Now it works fine.

Related

Unison: Ignore files with Regex doesn't work

I tried to ignore some files that end with ".NUMBERS" like .133443. I tried this Regex but it still copies the files:
unison -batch -owner -group -times -ignore "Regex ^*\.[0-9]+$" /hadoop/bigdata/giin/data ssh://cnp31ginhortonen1.giin.recouv//hadoop/bigdata/giin/data -prefer newer`
Source :
[root#cnp31ginhortonen1 .unison]# tree /hadoop/bigdata/giin/data/
/hadoop/bigdata/giin/data/
├── aefd.csv
├── aefd.log
├── aefd.xml
├── subdir
│   ├── aefd.csv
│   ├── aefd.log
│   ├── aefd.xml
│   └── TB5E.B01.117.210409074
├── TB5E.B01.117.10409074
└── TB5E.B01.117.210409074

Classpath conflict: org.clojure/clojure version 1.7.0 already loaded, NOT loading version 1.8.0

When copying a build.boot file from an old project to a new one I got the following error and found nothing on Google:
Classpath conflict: org.clojure/clojure version 1.7.0 already loaded, NOT loading version 1.8.0
You should just include [org.clojure/clojure "1.8.0"] with the same version as boot environment variable BOOT_CLOJURE_VERSION=1.8.0
into build.boot dependencies list.
Another way to get rid of this issues is to exclude clojure dependency from several dependencies in the list.
boot show -d
Will show your list of dependencies,
Classpath conflict: org.clojure/clojure version 1.8.0 already loaded, NOT loading version 1.7.0
2018-01-16 15:05:21.023:INFO::main: Logging initialized #6899ms
[adzerk/boot-cljs "2.1.4" :scope "test"]
[adzerk/boot-reload "0.5.2" :scope "test"]
[hiccup "1.0.5"]
[org.clojure/clojurescript "1.9.946"]
├── [com.google.javascript/closure-compiler-unshaded "v20170910"]
│ ├── [args4j "2.33"]
│ ├── [com.google.code.findbugs/jsr305 "3.0.1"]
│ ├── [com.google.code.gson/gson "2.7"]
│ ├── [com.google.errorprone/error_prone_annotations "2.0.18"]
│ ├── [com.google.guava/guava "20.0"]
│ ├── [com.google.javascript/closure-compiler-externs "v20170910"]
│ ├── [com.google.jsinterop/jsinterop-annotations "1.0.0"]
│ └── [com.google.protobuf/protobuf-java "3.0.2"]
├── [org.clojure/google-closure-library "0.0-20170809-b9c14c6b"]
│ └── [org.clojure/google-closure-library-third-party "0.0-20170809-b9c14c6b"]
├── [org.clojure/tools.reader "1.1.0"]
└── [org.mozilla/rhino "1.7R5"]
[org.clojure/data.json "0.2.6"]
[pandeiro/boot-http "0.8.3"]
└── [org.clojure/clojure "1.7.0"]
[ring/ring-core "1.6.3" :exclusions [[org.clojure/clojure]]]
├── [clj-time "0.11.0"]
│ └── [joda-time "2.8.2"]
├── [commons-fileupload "1.3.3"]
├── [commons-io "2.5"]
├── [crypto-equality "1.0.0"]
├── [crypto-random "1.2.0"]
└── [ring/ring-codec "1.0.1"]
└── [commons-codec "1.6"]
[ring/ring-jetty-adapter "1.6.3" :exclusions [[org.clojure/clojure]]]
├── [org.eclipse.jetty/jetty-server "9.2.21.v20170120"]
│ ├── [javax.servlet/javax.servlet-api "3.1.0"]
│ ├── [org.eclipse.jetty/jetty-http "9.2.21.v20170120"]
│ │ └── [org.eclipse.jetty/jetty-util "9.2.21.v20170120"]
│ └── [org.eclipse.jetty/jetty-io "9.2.21.v20170120"]
└── [ring/ring-servlet "1.6.3"]
As you can see here is:
[pandeiro/boot-http "0.8.3"]
└─[org.clojure/clojure "1.7.0"]
dependency, which boot is complaining on. So, what I did to get rid of this dependency is to make exclusion in build.boot like here:
[pandeiro/boot-http "0.8.3" :exclusions [org.clojure/clojure]]
so pandeiro/boot-http does not depend on old clojure version anymore and boot compain dissapeared.
Well the answer is pretty simple. I was missing the boot.properties file in the root folder. Just create a file with the following content:
#https://github.com/boot-clj/boot
#Sun Nov 01 16:34:27 CET 2015
BOOT_CLOJURE_NAME=org.clojure/clojure
BOOT_VERSION=2.7.1
BOOT_CLOJURE_VERSION=1.8.0

Bash filesname pattern detection and correction

I'm looking for the tools to detect a pattern in multiple files with the purpose to correct any heterogeneity. Precisely, this tool would help to generate the renaming scheme.
A correct pattern would be a mix of fixed patterns and increments followed by whatever and then an authorized extension.
Number of files ranges from 10 000 to 100 000, the solution should aim to minimize user intervention.
I have a directory like this :
testDir/
├── corrupttestfile100.ext
├── testfil0000.ext
├── testfil0001.ext
├── testfil0002.ext
├── testfil0003.ext
├── testfil0004.ext
├── testfil0005.ext
├── testfil0006.ext
├── testfil0007.ext
├── testfil0008.ext
├── testfil0009.ext
├── testfile010.ext
├── testfile011.ext
├── testfile012.ext
├── testfile013.ext
├── testfile014.ext
├── testfile015.ext
├── testfile016.ext
├── testfile017.ext
├── testfile018.ext
├── testfile019.ext
├── testfile020.ext
├── testfile021.ext
├── testfile022.ext
├── testfile023.ext
├── testfile024.ext
├── testfile025.ext
├── testfile026.ext
├── testfile027.ext
├── testfile028.ext
├── testfile029.ext
├── testfile030.ext
├── testfile031.ext
├── testfile032.ext
├── testfile033.ext
├── testfile034.ext
├── testfile035.ext
├── testfile036.ext
├── testfile037.ext
├── testfile038.ext
├── testfile039.ext
├── testfile040.ext
├── testfile041.ext
├── testfile042.ext
├── testfile043.ext
├── testfile044.ext
├── testfile045.ext
├── testfile046.ext
├── testfile047.ext
├── testfile048.ext
├── testfile049.ext
├── testfile050.ext
├── testfile051.ext
├── testfile052.ext
├── testfile053.ext
├── testfile054.ext
├── testfile055.ext
├── testfile056.ext
├── testfile057.ext
├── testfile058.ext
├── testfile059.ext
├── testfile060.ext
├── testfile061.ext
├── testfile062.ext
├── testfile063.ext
├── testfile064.ext
├── testfile065.ext
├── testfile066.ext
├── testfile067.ext
├── testfile068.ext
├── testfile069.ext
├── testfile080.ext
├── testfile081.ext
├── testfile082.ext
├── testfile083.ext
├── testfile084.ext
├── testfile085.ext
├── testfile086.ext
├── testfile087.ext
├── testfile088.ext
├── testfile089.ext
├── testfile090.ext
├── testfile091.ext
├── testfile092.ext
├── testfile093.ext
├── testfile094.ext
├── testfile095.ext
├── testfile096.ext
├── testfile097.ext
├── testfile098.ext
├── testfile099.ext
├── testfile101.ext2
└── testfileNotRelevant.ext
And I'd like to have the adequate tools to produce following feedback or equivalent :
1. pattern ^testfil matching 92/93
Exception :
corrupttestfile100.ext
2. pattern ^testfile matching 82/93
Exception :
corrupttestfile100.ext
testfil0000.ext
testfil0001.ext
testfil0002.ext
testfil0003.ext
testfil0004.ext
testfil0005.ext
testfil0006.ext
testfil0007.ext
testfil0008.ext
testfil0009.ext
3. Increment pattern breaks [70-79]
4. Increment pattern 3 digits 92/93
5. Increment pattern 4 digits 10/93
6. Extension exception : ext2 1/93
I began to scrip in bash using grep, find, sed and rename as it seemed natural but I'm wondering if will hit some walls and if I'm reinventing the wheel. I don't seem to find any relevant source of help and similar existing tools aren't open source nor data agnostic.

lein midje coudn't locate some file

I'm trying to do unit-testing using midje, and I hit some wall.
Assuming I have this directory structure:
├── src
│   └── clj
│   └── faris
│   └── lune
│   ├── core.clj
│   ├── index
│   │   ├── comment.clj
│   │   └── place.clj
│   ├── middleware
│      └── core.clj
└── test
└── clj
└── faris
└── lune
└── middleware
└── t_core.clj
which .../faris/lune/middleware/t_core.clj contains a simple test:
(ns faris.lune.middleware.t-core
(:require [faris.lune.middleware.core :refer :all]
[midje.sweet :refer :all]))
(fact "simple test"
(+ 1 1) => 2)
It always fail with the following error message:
Exception in thread "main" java.io.FileNotFoundException: Could not locate faris/lune/middleware/t_core__init.class or faris/lune/middleware/t_core.clj on classpath: , compiling:(/tmp/form-init2527989536148890974.clj:1:90)
at clojure.lang.Compiler.load(Compiler.java:7142)
at clojure.lang.Compiler.loadFile(Compiler.java:7086)
at clojure.main$load_script.invoke(main.clj:274)
at clojure.main$init_opt.invoke(main.clj:279)
at clojure.main$initialize.invoke(main.clj:307)
at clojure.main$null_opt.invoke(main.clj:342)
at clojure.main$main.doInvoke(main.clj:420)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:383)
at clojure.lang.AFn.applyToHelper(AFn.java:156)
at clojure.lang.Var.applyTo(Var.java:700)
at clojure.main.main(main.java:37)
Caused by: java.io.FileNotFoundException: Could not locate faris/lune/middleware/t_core__init.class or faris/lune/middleware/t_core.clj on classpath:
at clojure.lang.RT.load(RT.java:443)
at clojure.lang.RT.load(RT.java:411)
at clojure.core$load$fn__5066.invoke(core.clj:5641)
at clojure.core$load.doInvoke(core.clj:5640)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core$load_one.invoke(core.clj:5446)
at clojure.core$load_lib$fn__5015.invoke(core.clj:5486)
at clojure.core$load_lib.doInvoke(core.clj:5485)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invoke(core.clj:626)
at clojure.core$load_libs.doInvoke(core.clj:5524)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:626)
at clojure.core$require.doInvoke(core.clj:5607)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at midje.repl$load_facts$fn__7983.invoke(repl.clj:206)
at midje.repl$load_facts.doInvoke(repl.clj:192)
at clojure.lang.RestFn.invoke(RestFn.java:397)
at user$eval8046.invoke(form-init2527989536148890974.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:6703)
at clojure.lang.Compiler.eval(Compiler.java:6693)
at clojure.lang.Compiler.load(Compiler.java:7130)
... 11 more
Subprocess failed
Which is very cryptic to me, since it was like midje found the the test file, read the ns (faris.lune.middleware.t-core) and then saying it can't find it.
Any help? I must be missing something obvious.

Connecting to ClojureScript bREPL: clojure.browser.repl/connect throws TypeError in compiled JavaScript

I'm trying to connect to a ClojureScript browser REPL, and I'm having trouble with clojure.browser.repl/connect. My compiled JavaScript throws a TypeError trying to call appendChild on a null object in the block of Google Closure code at the top. I'm following the instructions in ClojureScript: Up and Running (Chapter 9, p.78, available in the preview), and wondering if the tooling for this has changed since it was published.
I'm using Leiningen 2.0.0, Java 1.6.0_37, OS X 10.7.5, plus the dependencies in my project.clj:
(defproject brepl-hello "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.4.0"]
[org.clojure/clojurescript "0.0-1552"]
[compojure "1.1.5"]
[ring/ring-jetty-adapter "1.1.8"]]
:plugins [[lein-cljsbuild "0.3.0"]]
:source-paths ["src/clj"]
:cljsbuild {:builds [{
:source-paths ["src/cljs"]
:compiler {
:output-to "resources/public/brepl-hello.js"
:optimizations :whitespace
:pretty-print true}}]})
Here's the only ClojureScript source file, src/cljs/brepl_hello/brepl-hello.cljs:
(ns brepl-hello
(:require [clojure.browser.repl :as repl]))
(repl/connect "http://localhost:9000/repl")
This compiles to the file resources/public/brepl-hello.js, which I've inserted into index.html in the same directory:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="brepl-hello.js"></script>
</head>
<body>
</body>
</html>
I've been serving this on port 3000 with Ring/Jetty from the REPL or Python SimpleHTTPServer. When I open this page in Chrome, the dev console shows Uncaught TypeError: Cannot call method 'appendChild' of null, with a traceback to this if/else block in the Google Closure code at the top of the complied js file, where parentElm (passed in to the containing function as a parameter) is null.
if(goog.userAgent.GECKO || goog.userAgent.WEBKIT) {
window.setTimeout(goog.bind(function() {
parentElm.appendChild(iframeElm);
iframeElm.src = peerUri.toString();
goog.net.xpc.logger.info("peer iframe created (" + iframeId + ")")
}, this), 1)
}else {
iframeElm.src = peerUri.toString();
parentElm.appendChild(iframeElm);
goog.net.xpc.logger.info("peer iframe created (" + iframeId + ")")
}
This seems to be a problem with clojure.browser.repl/connect. Swapping out this line in the ClojureScript source for something like:
(ns brepl-hello
(:require [clojure.browser.repl :as repl]))
(.write js/document "Hello World!")
Will compile and run in the browser just fine. I suspect something is misconfigured in my build settings or directory structure, or I'm making a noob mistake somewhere in all this. What's changed since the time the instructions I'm following were published? I found a couple references to this problem in the #clojure irc logs, but no solution.
Finally, here's an abbreviated directory tree for reference:
├── out
│   ├── cljs
│   │   ├── core.cljs
│   │   └── core.js
│   ├── clojure
│   │   └── browser
│   │   ├── event.cljs
│   │   ├── event.js
│   │   ├── net.cljs
│   │   ├── net.js
│   │   ├── repl.cljs
│   │   └── repl.js
│   └── goog
│   └── [...]
├── pom.xml
├── project.clj
├── resources
│   └── public
│   ├── brepl-hello.js
│   └── index.html
├── src
│   ├── clj
│   │   └── brepl_hello
│   │   └── core.clj
│   └── cljs
│   └── brepl_hello
│   └── brepl-hello.cljs
└─── target
   ├── brepl-hello-0.1.0-SNAPSHOT.jar
   ├── classes
   ├── cljsbuild-compiler-0
   │   ├── brepl_hello
   │   │   └── brepl-hello.js
    │   ├── cljs
   │   │   ├── core.cljs
   │   │   └── core.js
    │   └── clojure
   │   └── browser
   │   ├── event.cljs
   │   ├── event.js
   │   ├── net.cljs
   │   ├── net.js
    │   ├── repl.cljs
    │   └── repl.js
   └── stale
   └── extract-native.dependencies
Well, its open source and looking at the code it seems that document.body is null at the time the repl hidden iframe is being added to it (the connect call leads to this point).
You should do this connect call on dom ready or body on load and it should work fine.
Take a look at:
https://github.com/magomimmo/modern-cljs/blob/master/doc/tutorial-02.md
or, for a better brepl experience, here
https://github.com/magomimmo/modern-cljs/blob/master/doc/tutorial-18.md