technomancy/swank-clojure — Issue #86: I found out the reason and solution CDT 1.4.0a startedup failed on Windows 7  but encountered yet another problem athe same time.
Author: philos99
Created: 2011-12-07 10:03:40+00:00
State: open

First of all, the following is my clojure programming environment on Windows 7.

C:\work\lab\myproject\src\myproject> lein version
Leiningen 1.6.3-SNAPSHOT on Java 1.7.0_01 Java HotSpot(TM) Client VM

My first project.clj is as follows.

(defproject myproject "1.0.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.3.0"]]
:dev-dependencies [[swank-clojure "1.4.0-SNAPSHOT"]
[clojure-source "1.3.0-alpha5"]]
:jvm-opts ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n"]
:extra-classpath-dirs ["C:\\usr\\lang\\java\\jdk\\lib\\tools.jar"])

I typed the next contnets on the console.

C:\work\lab\myproject> lein swank
Listening for transport dt_socket at address: 50649
Connection opened on localhost port 4005.

The following is the contents of src/myproject/core.clj.

;; src/myproject/core.clj
(ns myproject.core)

(defn my-add [a b]
(+ a b))

After typing M-x slime-connect, I tried the following.

user> (use 'myproject.core)
nil

user> (my-add 10 20)
30

user> (use 'swank.cdt)
warning: unabled to add tools.jar to classpath. This may cause CDT initialization to fail.
CDT 1.4.0a startup failed: #
nil

At this time, my console shows the next message.

C:\work\lab\myproject> lein swank
Listening for transport dt_socket at address: 50649
Connection opened on localhost port 4005.
java.util.ServiceConfigurationError: com.sun.tools.attach.spi.AttachProvider: Pr
ovider sun.tools.attach.WindowsAttachProvider could not be instantiated: java.la
ng.UnsatisfiedLinkError: no attach in java.library.path

I searched the Internet for the solution hint and found the clue on the site
http://www.coderanch.com/t/377174/java/java/java-library-path

So I inserted the next newly added line on the project.clj, because the attach.dll was
in the folder C:\usr\lang\java\jdk\jre\bin.

(defproject myproject "1.0.0-SNAPSHOT"
:description "FIXME: write description"
:dependencies [[org.clojure/clojure "1.3.0"]]
:dev-dependencies [[swank-clojure "1.4.0-SNAPSHOT"]
[clojure-source "1.3.0-alpha5"]]
:jvm-opts ["-agentlib:jdwp=transport=dt_socket,server=y,suspend=n"
"-Djava.library.path=C:\\usr\\lang\\java\\jdk\\jre\\bin"] ;; <== newly added line
:extra-classpath-dirs ["C:\\usr\\lang\\java\\jdk\\lib\\tools.jar"])

And then I restarted lein swank and had the next result.

user> (use 'myproject.core)
nil

user> (my-add 10 20)
30

user> (use 'swank.cdt)
warning: unabled to add tools.jar to classpath. This may cause CDT initialization to fail.
Clearing CDT event requests and continuing.
Swank CDT release 1.4.0a started
nil

And I confirmed on the console that swank.cdt successfully startd on Windows 7.
This is one solution I found out on the Swank startup failure on Windows 7.

C:\work\lab\myproject> lein swank
Listening for transport dt_socket at address: 53044
Connection opened on localhost port 4005.
CDT ready

Stil I met another problem.

user> (set-bp my-add) ;; This doesn't work
No message.
[Thrown class java.lang.NullPointerException]

;; This seems to work, but I'm not sure of it
;; because of the next message on Mini buffer.
user> (set-bp myproject.core/my-add)
nil
nil

;; The message on Minibuffer
error in process filter: Wrong number ofarguments: nil, 2

Anyway I continues my experiment as follows.

user> (my-add 20 30)

And then the next window titled \*sldb clojure/2\* showed up.

CDT BreakpointEvent in thread Swank REPL Thread
From here you can: e/eval, v/show source, s/step, x/next, o/exit func

Restarts:
0: [QUIT] Quit to the SLIME top level

Backtrace:
0: myproject.core$my_add.invoke(core.clj:3)
1: user$eval2732.invoke(NO_SOURCE_FILE:1)
2: clojure.lang.Compiler.eval(Compiler.java:6465)
3: clojure.lang.Compiler.eval(Compiler.java:6431)
4: clojure.core$eval.invoke(core.clj:2795)
5: swank.core$eval680$fn__681.invoke(core.clj:409)
6: clojure.lang.MultiFn.invoke(MultiFn.java:163)
7: swank.commands.basic$eval_region.invoke(basic.clj:48)
8: swank.commands.basic$eval_region.invoke(basic.clj:38)
9: swank.commands.basic$eval901$listener_eval__902.invoke(basic.clj:72)
10: clojure.lang.Var.invoke(Var.java:401)
11: user$eval2730.invoke(NO_SOURCE_FILE)
12: clojure.lang.Compiler.eval(Compiler.java:6465)
13: clojure.lang.Compiler.eval(Compiler.java:6431)
14: clojure.core$eval.invoke(core.clj:2795)
15: swank.core$eval_in_emacs_package.invoke(core.clj:94)
16: swank.core$eval_for_emacs.invoke(core.clj:241)
17: clojure.lang.Var.invoke(Var.java:409)
18: clojure.lang.AFn.applyToHelper(AFn.java:167)
19: clojure.lang.Var.applyTo(Var.java:518)
20: clojure.core$apply.invoke(core.clj:600)
21: swank.core$eval_from_control.invoke(core.clj:101)
22: swank.core$eval_loop.invoke(core.clj:106)
23: swank.core$spawn_repl_thread$fn__639$fn__640.invoke(core.clj:320)
24: clojure.lang.AFn.applyToHelper(AFn.java:159)
25: clojure.lang.AFn.applyTo(AFn.java:151)
26: clojure.core$apply.invoke(core.clj:600)
27: swank.core$spawn_repl_thread$fn__639.doInvoke(core.clj:317)
28: clojure.lang.RestFn.invoke(RestFn.java:397)
29: clojure.lang.AFn.run(AFn.java:24)
30: java.lang.Thread.run(Unknown Source)

I didnt' have any choide but to do type 0 here.

And then I encountered the new empty window titled myproject%5ccore.clj, where
%5c seems to mean the ascii 0x5c backslash character code in my opinion.
And then I returned to *simple-repl-clojure* buffer and found the answer 50
(the result of (my-add 20 30)).

and Then I retried the following experiment, adding the namespace
'myproject.core' to 'my-add' function.

user> (myproject.core/my-add 20 30)

I encountered again the next *sldb clojure/3* window which has

CDT BreakpointEvent in thread Swank REPL Thread
From here you can: e/eval, v/show source, s/step, x/next, o/exit func

Restarts:
0: [QUIT] Quit to the SLIME top level

Backtrace:
0: myproject.core$my_add.invoke(core.clj:3)
1: user$eval2744.invoke(NO_SOURCE_FILE:1)
2: clojure.lang.Compiler.eval(Compiler.java:6465)
3: clojure.lang.Compiler.eval(Compiler.java:6431)
4: clojure.core$eval.invoke(core.clj:2795)
5: swank.core$eval680$fn__681.invoke(core.clj:409)
[No Locals]
6: clojure.lang.MultiFn.invoke(MultiFn.java:163)
7: swank.commands.basic$eval_region.invoke(basic.clj:48)
8: swank.commands.basic$eval_region.invoke(basic.clj:38)
9: swank.commands.basic$eval901$listener_eval__902.invoke(basic.clj:72)
10: clojure.lang.Var.invoke(Var.java:401)
11: user$eval2742.invoke(NO_SOURCE_FILE)
12: clojure.lang.Compiler.eval(Compiler.java:6465)
13: clojure.lang.Compiler.eval(Compiler.java:6431)
14: clojure.core$eval.invoke(core.clj:2795)
15: swank.core$eval_in_emacs_package.invoke(core.clj:94)
16: swank.core$eval_for_emacs.invoke(core.clj:241)
17: clojure.lang.Var.invoke(Var.java:409)
18: clojure.lang.AFn.applyToHelper(AFn.java:167)
19: clojure.lang.Var.applyTo(Var.java:518)
20: clojure.core$apply.invoke(core.clj:600)
21: swank.core$eval_from_control.invoke(core.clj:101)
22: swank.core$eval_loop.invoke(core.clj:106)
23: swank.core$spawn_repl_thread$fn__639$fn__640.invoke(core.clj:320)
24: clojure.lang.AFn.applyToHelper(AFn.java:159)
25: clojure.lang.AFn.applyTo(AFn.java:151)
26: clojure.core$apply.invoke(core.clj:600)
27: swank.core$spawn_repl_thread$fn__639.doInvoke(core.clj:317)
28: clojure.lang.RestFn.invoke(RestFn.java:397)
29: clojure.lang.AFn.run(AFn.java:24)
30: java.lang.Thread.run(Unknown Source)

And the next message on the minibuffer showed up.

File C:/work/lab/myproject/src/myproject%5ccore.clj no longer exists!

To sum up, in my guess, the first problem is that swank-clojure doesn't process
the backslash character code properly.

And the second problem is that swank-cdt doesn't recognize src/myproject/core.clj
unless I specificy it explicitly, as in the case (myproject.core/my-add 20 30) in my experiment.