17
votes

Trying to import a class outside the java-library with no result. I'm runnig counterclockwise on Eclipse Helios. The commons-land-2.6.jar is in the buildpath. I'm new to Clojure and can't figure this out. All help greatly appreciated!

Naturally this works fine:

1:7 exp2=> (import '(java.io FileReader))

> java.io.FileReader

but this doesn't:

1:6 exp2=> (import '(org.apache.commons.lang.StringUtils))

> nil

This is the ultimate goal:

1:10 exp2=> (defn whitespace? [character] (. StringUtils (isEmpty character )))

> java.lang.Exception: Unable to resolve symbol: StringUtils in this context (repl-1:10)

1

1 Answers

27
votes

You made one error - you didn't put space between org.apache.commons.lang and StringUtils class. This form of import allows you to import several classes from one package, for example:

(import '(org.apache.commons.lang StringUtils SystemUtils))

if you want to import only one class, then you can use version without parentheses:

(import 'org.apache.commons.lang.StringUtils)

And because functions in StringUtils are static, you need to use following code:

(StringUtils/isEmpty character)

to invoke their functions