3
votes

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.

2
Odd that you specify Clojure 1.5.1 in your project, but it has clojure 1.4.0 in your lein classpath output. Also, Clojure Contrib was deprecated and you should instead import distinct modules.noahlz

2 Answers

2
votes

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
0
votes

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.