tags:

views:

93

answers:

3

I seem to be doing something wrong. I've built clojure from git, and am invoking it thus:

java -cp clojure.jar clojure.main

I get the repl, and then I type:

(import 'java.lang.string)

and I get:

java.lang.ClassNotFoundException: java.lang.string (NO_SOURCE_FILE:1)

I'm trying this with lang.string since I assume it has to exist on the classpath somewhere. I've tried other libraries, all without much luck. What am I doing wrong?

+2  A: 

Bleh, I think I found it. First of all the syntax should be:

(import java.lang.String)

Also notice it's String not string.

Timothy Baldridge
No. The quote is necessary for import. See Brian's answer. But not for ns clauses. See Bozhidar's answer.
kotarak
Actually the quote is not needed for import as well. At least in clojure 1.1, that I'm using...
Bozhidar Batsov
+7  A: 

String should be capitalized, that's all.

user> (import 'java.lang.String)
java.lang.String

But everything in java.lang is already imported and available by default, so you shouldn't need to do this.

Brian Carper
+2  A: 

Btw in non repl exercises probably the best way to include Java classes is the ns macro.

(ns foo.bar
  (:refer-clojure :exclude [ancestors printf])
  (:require (clojure.contrib sql sql.tests))
  (:use (my.lib this that))
  (:import (java.util Date Timer Random)
           (java.sql Connection Statement))) 
Bozhidar Batsov