installing compojure - clojure

Following the instructions in http://en.wikibooks.org/wiki/Compojure/Getting_Started, I:
downloaded http://github.com/weavejester/compojure/tarball/0.3.2
extracted to ~/compojure
chdir to there
changed permission to executable
run ant deps
ant
run export CLASSPATH=~/compojure/compojure.jar
created compojure shell script
Clojure source file
chdir to there
run ./compojure hello.clj
Then, I got:
Exception in thread "main" java.lang.NoClassDefFoundError: clojure/lang/Script
Caused by: java.lang.ClassNotFoundException: clojure.lang.Script
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: clojure.lang.Script. Program will exit.
I tried changing Compojure shell script to use full classpath, but still didn't work.
Why not? How to install Compojure?

That page is outdated.
You should follow these instructions from compojure developers:
https://github.com/weavejester/compojure/wiki/Getting-Started

Related

Cursive editor gives classpath exception when trying to run clojure project that uses figwheel

Trying to get a project that uses figwheel running in Cursive. I can get everything running on the command line using run -m clojure.main script/figwheel.clj but when I follow the instructions for running within Cursive I get the following error:
java.io.FileNotFoundException: Could not locate figwheel_sidecar/repl_api__init.class or figwheel_sidecar/repl_api.clj on classpath.
Does anyone know why this works on the command line and not within Cursive? I believe I followed the directions that the project provided. Do I need to set my classpath somewhere in Cursive.

Hadoop BigTop on centOS. Not able to run MapReduce Application - FlightsByCarrier

I am learning Hadoop using the Hadoop for Dummies. I have successfully run thr first steps like installation, creating HDFS and storing Data, running Pig scripts etc.
I have created the FlightsByCarries.jar File.
When I run the code as given in the book, I am getting an error:
[root#localhost totalmiles]# hadoop jar /home/tom/Desktop/totalmiles/FlightsByCarrier.jar FlightsByCarrier /user/root/airline-data/2008.csv /user/root/output/flightsCount
Exception in thread "main" java.lang.ClassNotFoundException: FlightsByCarrier
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
at org.apache.hadoop.util.RunJar.main(RunJar.java:205)
Could someone please help me correct this?
it is because your compiler is not getting your main method in the jar FlightsByCarrier. may be you haven't copy the file to hdfs or your file path is not appropriate...check once..and then try
You JAR file is unable to locate the main class name, if you are using any package name in your main class then specify complete name along with package while running the program.
Ex:
hadoop jar FlightsByCarrier.jar com.dev.FlightsByCarrier /input /output
You can also include main class while creating JAR file.
While creating a JAR file after selecting the path then click next --> asks for selecting main class --> browse the name and select --> click OK
Run the command without class name in this case.
hadoop jar FlightsByCarrier.jar /input /output
Hope this solves your problem.

Getting an exception when trying to run lein

I get the following exception when trying to run lein in linux.
Exception in thread "main" java.lang.NoClassDefFoundError: clojure.core.protocols$fn__5393
at java.lang.Class.initializeClass(libgcj.so.10)
at clojure.core.protocols__init.load(Unknown Source:16)
at clojure.core.protocols__init.<clinit>(Unknown Source)
at java.lang.Class.initializeClass(libgcj.so.10)
at java.lang.Class.forName(libgcj.so.10)
at clojure.lang.RT.loadClassForName(RT.java:1578)
at clojure.lang.RT.load(RT.java:399)
at clojure.lang.RT.load(RT.java:381)
at clojure.core$load$fn__4519.invoke(core.clj:4915)
at clojure.core$load.doInvoke(core.clj:4914)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at clojure.core__init.load(Unknown Source:5342)
at clojure.core__init.<clinit>(Unknown Source)
at java.lang.Class.initializeClass(libgcj.so.10)
at java.lang.Class.forName(libgcj.so.10)
at clojure.lang.RT.loadClassForName(RT.java:1578)
at clojure.lang.RT.load(RT.java:399)
at clojure.lang.RT.load(RT.java:381)
at clojure.lang.RT.doInit(RT.java:416)
at clojure.lang.RT.<clinit>(RT.java:302)
at java.lang.Class.initializeClass(libgcj.so.10)
at clojure.main.<clinit>(main.java:20)
at java.lang.Class.initializeClass(libgcj.so.10)
at java.lang.Class.forName(libgcj.so.10)
at java.lang.Class.forName(libgcj.so.10)
at jline.ConsoleRunner.main(ConsoleRunner.java:69)
Caused by: java.lang.VerifyError: verification failed at PC 214 in
clojure.core.protocols$fn__5393:invoke((Ljava.lang.Object;Ljava.lang.Object;Ljava.lang.Obje ct;)Ljava.lang.Object;): incompatible type on stack
at java.lang.Class.initializeClass(libgcj.so.10)
...25 more
I've followed the instructions on their github page, but no luck. I thought it would be fun to start learning clojure today but instead I've had nothing but problems, I don't even know what leiningen is, other than I apparently have to have it.
sorry about the frusteration,
Leiningen is a build tool to take the pain out of getting hacking on a new clojure project.
Before leiningen existed many people would try to "install" clojure by downloading a jar file out build it from source. Instead of doing any of that you just specify the version you want to use in the leiningen project.clj file and it installs it locally as a dependency for that project.
have you run:
lein new hello_clojure
cd hello_clojure
edit project.clj and set it to use clojure 1.3.0 :dependencies [[org.clojure/clojure "1.3.0"]
lein deps
lein repl
(+ 1 2 3 4)
When things go wrong with leiningen I generally:
lein upgrade
rm lib/*
lein deps
Problems like this are uncommon (for me) and usually fairly specific, so perhaps you would do well to drop into #clojure on irc.freenode.net and ask. It's a very friendly croud dont worry.

Is Clojure installable this way?

I downloaded Clojure 1.2 https://github.com/downloads/clojure/clojure/clojure-1.2.0.zip , extracted it under /Library directory, created CLOJURE_HOME, added $CLOJURE_HOME/script to my $PATH.
When I'm trying to run clj or repl scripts that are located under script directory, I'm getting this error:
Exception in thread "main" java.lang.NoClassDefFoundError: jline/
ConsoleRunner
Caused by: java.lang.ClassNotFoundException: jline.ConsoleRunner
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Ok, jline.jar isn't in the CLASSPATH so I checked clj and repl scripts:
CLASSPATH=src/clj:test:test-classes:classes/:script/jline-0.9.94.jar:../clojure-contrib/target/clojure-contrib-1.2.0-SNAPSHOT.jar
if [ -z "$1" ]; then
exec java -server jline.ConsoleRunner clojure.main
else
SCRIPT=$(dirname $1)
export CLASSPATH=$SCRIPT/*:$SCRIPT:$CLASSPATH
exec java -Xmx3G -server clojure.main "$1" "$#"
fi
I downloaded jline.jar under $CLOJURE_HOME/script but I'm still getting the same error.
This lead me to the question:
What is the role of https://github.com/downloads/clojure/clojure/clojure-1.2.0.zip anyway?
Is it supposed to be used to install Clojure? or just to to build and get clojure.jar?
I noticed no one is talking about installing Clojure this way.
Am I missing something?
Clojure, being a JVM language, has to deal with the JVM classpath. This makes 'installing' it a bit unwieldy and confusing. Rather than install it yourself like this, try out some tools like cljr and cake. I wrote a blog post about this that might be helpful: http://blog.raynes.me/?p=48
In summary: Check out cljr, cake, and leiningen.
The majority of people in the Clojure community don't have Clojure 'installed'. Most people use a build tool and/or cljr. It doesn't make a lot of sense to install Clojure to a central place when, inevitably, you're going to need dependency management, and jars will be copied around everywhere anyway. In any case, it's much easier to let a tool handle the classpath for you.
the clojure.zip file exists so people who write tools will have a place for their tools to get the parts they need ;)
For people not writing tools they are either working on/with the latest branch from github and so they get Clojure with a git pull or they are using the above mentioned liningen, cake, cljr , counterclockwise(eclipse), la clojure (intellij), or netbeans.

How to run clojure on Mac OS X?

I'm following the examples from the book 'Programming Clojure', and I'm at page
17 to run (require 'example.introduction).
I have set clojure at ~/bin/clojure as follows
java -server \
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8888 -cp ... clojure.lang.Repl
The -cp contains . (current directory). When I try it with clojure, I get the following error message.
Exception in thread "main" java.lang.ExceptionInInitializerError
at clojure.lang.Repl.(Repl.java:23)
Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodError: clojure.lang.MultiFn.(Ljava/lang/String;Lclojure/lang/IFn;Ljava/lang/Object;Lclojure/lang/IRef;)V (utils.clj:0)
at clojure.lang.RT.(RT.java:290)
... 1 more
Caused by: java.lang.NoSuchMethodError: clojure.lang.MultiFn.(Ljava/lang/String;Lclojure/lang/IFn;Ljava/lang/Object;Lclojure/lang/IRef;)V (utils.clj:0)
at clojure.lang.Compiler.eval(Compiler.java:4153)
at clojure.lang.Compiler.load(Compiler.java:4470)
at clojure.lang.RT.loadResourceScript(RT.java:327)
at clojure.lang.RT.loadResourceScript(RT.java:316)
at clojure.lang.RT.load(RT.java:406)
at clojure.lang.RT.load(RT.java:376)
at clojure.core$load__4557$fn__4559.invoke(core.clj:3427)
at clojure.core$load__4557.doInvoke(core.clj:3426)
at clojure.lang.RestFn.invoke(RestFn.java:413)
at clojure.core$load_one__4520.invoke(core.clj:3271)
...
at clojure.lang.RT.loadResourceScript(RT.java:327)
at clojure.lang.RT.loadResourceScript(RT.java:312)
at clojure.lang.RT.maybeLoadResourceScript(RT.java:308)
at clojure.lang.RT.doInit(RT.java:430)
at clojure.lang.RT.(RT.java:286)
... 1 more
Caused by: java.lang.NoSuchMethodError: clojure.lang.MultiFn.(Ljava/lang/String;Lclojure/lang/IFn;Ljava/lang/Object;Lclojure/lang/IRef;)V
at clojure.contrib.duck_streams__init.load(Unknown Source)
at clojure.contrib.duck_streams__init.(Unknown Source)
...
at clojure.lang.Compiler.eval(Compiler.java:4142)
... 28 more
I tried to run clojure as follows.
alias clojure='java -jar $JARDIR/clojure.jar '
But it doesn't have the CLASSPATH that I setup in .bashrc correctly, when I run the command as follows.
(println (seq (.getURLs (java.lang.ClassLoader/getSystemClassLoader))))
What might be wrong?
The easiest way is to use Stuart Halloway's code that accompanies the book:
Clone Stu's code from GitHub: $ git clone http://github.com/stuarthalloway/programming-clojure.git
cd into the programming-clojure directory that was created: $ cd programming-clojure
Run the repl.sh script in the bin/ directory: $ ./bin/repl.sh (make sure you run it from the repo root, not the bin/ directory, otherwise it won't work).
The script will set up all the necessary paths, including the paths to the examples in the book.
(You can do it manually, of course, but at any rate, you have to download or clone the programming-clojure source code anyway for the examples to work.)