GUI Using Seesaw - clojure

I am trying to make a small window using Seesaw for Clojure. I have created a project "sample" using Leiningen.
lein new app sample
I have made added the dependency in the project file.
(defproject sample "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"] [seesaw "1.4.4"]]
:main ^:skip-aot sample.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all}})
My source file is as follows:
(ns sample.core
(:gen-class)
(:require [seesaw.core :as seesaw]
[seesaw.dev :as dev]))
(def window (seesaw/frame
:title "First Example"
:content "hello world"))
(dev/show-options window)
But when I run it I keep getting an error: clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: No such namespace: dev, compiling:(C:\Users\A\sample\src\sample\core.clj:10:1)

I followed your instructions and it worked fine for me, so long as I left the -main definition in place.

Related

FileNotFoundException with Leiningen and Ring

I'm currently using Leiningen and Ring through the command line on a project I'm making called reagent_test, and I ran into a problem:
C:/...reagent_test>lein ring server
... huge chunk of errors
Caused by: java.io.FileNotFoundException: Could not locate reagent_test/core__init.class or reagent_test/core.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.
... more errors
If anyone wants a gist for the issue, I'll make one if needed.
The problem is, the files are all in the right place. Here's my project.clj:
(defproject reagent-test "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"}
:plugins [[lein-cljsbuild "1.1.5"]
[lein-ring "0.10.0"]]
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.9.456"]
[ring "1.4.0"]
[leiningen "2.7.1"]
[reagent "0.6.0"]
[garden "1.3.2"]]
:cljsbuild {:builds {:app {:source-paths ["src/cljs"]}
:compiler {:output-to "resources/public/main.js"
:pretty-print true}}}
:ring {:handler reagent-test.core/-main})
And my project structure is like this (at least, for the relevant files):
src:
clj:
reagent_test:
core.clj
cljs:
reagent_test:
core.cljs
project.clj
In both core.clj and core.cljs I have this as my namespace:
(ns reagent-test.core)
NOTE: Folders have a colon and files don't.
In the namespace declaration at the top of the file you should use a dash:
(ns reagent-test.core)
Whereas the file (and all the directories above the file) should use underscores. So the filename should be whatever/reagent_test/core.clj or whatever/reagent_test/core.cljs.
As Chris Murphy has pointed out in the comments of his answer. Since you have changed your project directory structure a little, you will need to modify your project.clj file:
(defproject reagent-test "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"}
:plugins [[lein-cljsbuild "1.1.5"]
[lein-ring "0.10.0"]]
:source-paths ["src/clj"]
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.9.456"]
[ring "1.4.0"]
[leiningen "2.7.1"]
[reagent "0.6.0"]
[garden "1.3.2"]]
:cljsbuild {:builds {:app {:source-paths ["src/cljs"]}
:compiler {:output-to "resources/public/main.js"
:pretty-print true}}}
:ring {:handler reagent-test.core/-main})
The addition is the :source-paths key which should specify the directory for the Clojure code. By default lein uses the src directory as the root for the Clojure source files.

Compilation error including clj-time in project

I have included [clj-time "0.8.0"] in my project.clj. I then refer to clj-time in my namespace like so:
(ns school-finder.tasks
(:require [clj-time.core :as t]))
However when I try and run the project I get the following compilation error:
Exception in thread "main" java.lang.IllegalArgumentException: No single method: second of interface: clj_time.core.DateTimeProtocol found for function: second of protocol: DateTimeProtocol, compiling:(clj_time/coerce.clj:146:64)
What am I doing wrong?
I think this is a known bug: https://github.com/clj-time/clj-time/issues/124
If you just do a lein clean (possibly followed by a lein deps) that should solve it.
It's hard to say where the problem is, so here's a working example:
project.clj:
(defproject hello "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.5.1"]
[clj-time "0.8.0"]]
:source-paths ["dev"])
src/hello/core.clj:
(ns hello.core
(:require [clj-time.core :as t]))
(println (t/now))

Clojure REPL environment lost after running refresh-all

I'm hacking on a Clojure app I created with lein new app inclojure. There are a few things I'd like to pre-load every time I fire up the REPL, so I created a dev/user.clj file, and source it in my project.clj:
(defproject inclojure "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.5.1"]]
:main ^:skip-aot inclojure.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all}
:dev {:source-paths ["dev"]}})
The file mostly just requires a bunch of crap so I can use shorthand:
(ns inclojure.core
(:require [clojure.java.io :as io]
[clojure.tools.namespace.repl :refer (refresh-all)])
(:use [clojure.reflect :only [reflect]]
[clojure.pprint :only [pprint print-table pp]]))
(defn r
"inspect all of the properties in a java object, optionally by specifying a
pattern"
([o] (r o "."))
([o prefix]
(->> (reflect o :ancestors true)
:members
(filter #(re-find (re-pattern (str "(?i)" prefix)) (str (:name %))))
(pprint))))
This all works, but when I run (refresh-all), it loses everything from dev/user.clj. Is there a way for me to be able to (refresh-all) from the and either keep or re-load everything from dev/user.clj?
It seems like I may want to create a REPL-specific namespace like inclojure.repl in dev/user.clj, and then make that the REPL's init-ns.

Clojure's :require and Instaparse

I am trying to use instaparse lib for my clojure project. I use leiningen 2.0 and clojure 1.5.1 in my project dependencies. I add instaparse to my project dependencies as follow:
(defproject bachelor "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.5.1"]
[org.clojure/clojure-contrib "1.2.0"]
[instaparse "1.1.0"]])
And that is my source where i'm trying to require that lib:
(ns bachelor.data
(:require [clojure.string :as str])
(:require [instaparse.core :as insta])
(:use [clojure.contrib.generic.math-functions])
)
When I try to compile that I get following error message:
cd c:/bachelor/src/bachelor.data/ 1 compiler notes:
Unknown location: error: java.io.FileNotFoundException: Could not
locate instaparse/core__init.class or instaparse/core.clj on
classpath:
company.clj:1:1: error: java.io.FileNotFoundException: Could not
locate instaparse/core__init.class or instaparse/core.clj on
classpath: (company.clj:1)
Compilation failed.
I checked classpath for my project and I think that instaparse should be found there.
lein classpath
C:\bachelor\test;C:\bachelor\src;C:\bachelor\dev-resources;C:\bachelor\resources;C:\bachelor\target\classes;C:\Users\Maciej.m2\repository\instaparse\instaparse\1.1.0\instaparse-1.1.0.jar;C:\Users\Mac
iej.m2\repository\org\clojure\clojure-contrib\1.2.0\clojure-contrib-1.2.0.jar;C:\Users\Maciej.m2\repository\org\clojure\clojure\1.5.1\clojure-1.5.1.jar
Have any idea what I am doing wrong?
UPDATE
I updated result for lein classpath. Earlier, I've pasted old result.
here is a working sample project:
project.clj:
(defproject parse "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.5.1"]
[instaparse "1.1.0"]])
you don't need the lines for contrib, and string is built into clojure now.
src/parse/core.clj:
(ns parse.core
(:require [instaparse.core :as insta]
[clojure.string :as str]))
(def as-and-bs
(insta/parser
"S = AB*
AB = A B
A = 'a'+
B = 'b'+"))
repl:
#<Namespace parse.core>
parse.core> (as-and-bs "aaaaabbbaaaabb")
[:S [:AB [:A "a" "a" "a" "a" "a"] [:B "b" "b" "b"]] [:AB [:A "a" "a" "a" "a"] [:B "b" "b"]]]
parse.core> (str/join "," ["a" "b" "c"])
"a,b,c"
My general Liningen strangeness resolution checklist:
run lein deps and restart nrepl/emacs
lein clean and restart nrepl/emacs
remove the local libs dir (lein v1.x)
remove my local maven repository and run lein deps
I've found out what was wrong. I was creating project with leiningen but develop source with Clojure-box or Clooj. I was also trying to compile my source with that tools and it was mistake. When you run such IDE it loads that's own classpath and that is why it could not find library I'd like to use. Now I compile my src with
lein compile
and run it in
lein repl
and everything is just working fine.

hiccup form-helper with compojure

Exception: Exception in thread "main" java.io.FileNotFoundException: Could not locate hiccup/form_helpers__init.class or hiccup/form_helpers.clj on classpath:
I'm trying to get a toy compojure app up and running. The original app was from CloudBees and their ClickStart app for Clojure/Compojure. I'm trying to add a simple form (that won't persist anything yet) using hiccup form_helpers but I'm getting a ClassNotFound exception. Here's what I've done:
project.clj:
(defproject mywebapp "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:dependencies [[org.clojure/clojure "1.4.0"]
[compojure "1.1.1"]
[hiccup "1.0.1"]]
:plugins [[lein-ring "0.7.3"]]
:ring {:handler mywebapp.routes/app}
:profiles
{:dev {:dependencies [[ring-mock "0.1.3"]]}})
views.clj:
(ns mywebapp.views
(:use [hiccup core page]
[hiccup form-helpers :only [form-to label text-area submit-button]]))
...
(defn shout-form []
[:div {:id "shout-form" }
(form-to [:post "/form"]
(label "shout" "What do you want to SHOUT?")
[:br]
(text-area "shout")
[:br]
(submit-button "SHOUT!"))])
...
Ah, looks like I just had an old example of forms in hiccup. form_helpers was from a previous version.
if I change my views.clj file from this:
(:use [hiccup form-helpers])
to look like this:
(:use [hiccup form])
(and presumably this would work though i haven't tested it):
(:use [hiccup form :only [form-to label text-area submit-button]])
I don't get the error anymore.
To clarify: the package used to be called "form_helpers" and is now simply called "form".