7

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?

3 Answers 3

15

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.

Sign up to request clarification or add additional context in comments.

Comments

8

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))) 

Comments

2

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

(import java.lang.String)

Also notice it's String not string.

2 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.