How to Execute Clojure File? - windows

How can I run a clojure file/script, which uses clojure-contrib, from the command line? My (winodws) machine has clojure-1.2.1.jar and clojure-contrib-1.2.0.jar on the classpath. Note: I can start the REPL with: java clojure.mainand I can execute *.clj files that DO NOT use clojure-contrib with: java clojure.main file-name.clj

You need to add the clojure-contrib jar to the classpath. Since you are using windows, you add multiple classpaths by separating the entries with semicolons.
java -cp clojure-1.2.1.jar;clojure-contrib-1.2.0.jar clojure.main file-name.clj
The above code should enable you to run your file-name.clj script which depends on clojure-contrib.

This line will run a clojure script "hello-world.clj". It first adds the clojure jar to the class path first and then will execute the file.
java -cp clojure.jar clojure.main hello-world.clj

for those used to text editor + lots of shell work
lein run isn't bad
and lein projects can help you organize deps and other proj-specific

Related

How do I run a java program in cmd?

I have created a program in Java, but it is not taking the inputs correctly in edit-plus(compiler) so now I want it to run in cmd. My JSK file is at : C:\Program Files\Java\jdk1.7.0_21\bin and my Java file is at: C:\TurboC4\TC\java new programs
Please tell me the steps to run it in cmd.
On the command line use:
java -jar path/to/your/jar_file.jar
if you do not have a jar file, than you have to compile first your Java classes:
javac -g Foo.java
if you have just a single file (containing a static void main()) than you can simply run it with:
java path/to/your/compiled_class_file [<command line args>, ...]
Note: Run the command above without .class extension. i.e.
java Foo
if you want to generate a jar file from your compiled .class files run:
jar cf jar-file input-file(s)
However, I would recommend you to use a IDE that compiles, packs and runs your code for you automatically with one click. i.e. IntelliJ or Eclipse
If your class is not into a package and is compiled as java.class in C:\TurboC4\TC\:
cd C:\TurboC4\TC\
C:\Program Files\Java\jdk1.7.0_21\bin java
If you just want to run your single java class as a command line program, then the answer is in This question.
Example:
java my.class.HelloWorld
If you have compiled an entire java project into a JAR file, check this Stackoverflow question for the answer.
Example:
java -cp c:\location_of_jar\myjar.jar com.mypackage.myClass

How do I run PigUnit on the command line

It isn't clear to me how to run PigUnit on the command line. I've seen some documentation that mentions some interaction with JUnit, but I don't have much experience with it.
So, if I have pigunit.jar, junit.jar and my PigUnitTests.jar in the same folder, how do I run PigUnit on the command line?
Using pig-0.10.0
You actually want to run jUnit, so assuming your jars are in the current directory, use:
java -cp ./pigunit.jar:./junit.jar:./PigUnitTests.jar org.junit.runner.JUnitCore <Your.Test.ClassName>

Clojure REPL in Windows

I would like to learn Clojure, but rather than opening up a full-on IDE each time I'd like to be able to have a batch file (or similar) that opens up a decent REPL for quickly hacking examples. (i.e. I'm not looking for an Emacs/Netbeans/Eclipse IDE discussion).
For instance, this starts up the most basic REPL:
cd C:\Program Files\Java\clojure-1.2.0\
java -cp clojure.jar clojure.main
and if you add the jline and clojure-contrib jar files to the clojure directory then
cd C:\Program Files\Java\clojure-1.2.0\
java -cp .;jline-0_9_5.jar;clojure.jar;clojure.contrib.jar jline.ConsoleRunner clojure.main
Take a look at leiningen. From there, download the windows zip, put the lein directory in your PATH and run:
lein repl
Enjoy!
For a stand alone repl with decent classpath management take a look at cljr:
https://github.com/liebke/cljr
This provides a cljr.bat script that works very nicely under windows and provides convenient management of what is on the classpath and the ability to downloand/install clojure packages.

Setting the classpath

hi i have written one shell script which is performing 1 task.
java -jar abc.jar $* -adminid $j_username
before this command i want to set classpath(or want to refer) of all jars which are in particular lib folder, how to do that?
set CLASSPATH=pathtojars1;pathtojars2
before your java command.
Or:
java -classpath
One way to do it would be:
set CP=abc.jar:someother.jar
java -cp $CP your.main.Class $* -adminid $j_username
It is worth while to note that when using -jar you can't specify other JARs/resources on the classpath i.e. -cp switch is ignored hence you would have to choose between the two.
Create a standalone JAR which
incorporates other JARs/resources
Have different JAR files but instead
of using -jar specify the main
class when running the program

How to run Clojure tests on Windows?

I put Clojure in C:\clojure-1.1.0, and start the REPL by:
java -cp clojure.jar clojure.main
In \test\clojure\test_clojure, there are a bunch of test files.
How to run these?
For example, I tried:
java -cp ......\clojure.jar clojure.main data_structures.clj
And it didn't work.
Two choices:
Once the REPL starts you can manually load the file with:
(load-file "\data_structures.clj")
You can pass a command-line option telling it to load/eval a file upon boot:
java -cp clojure.jar clojure.main -i \data_structures.clj -e "(do-stuff)"
We use (clojure 1.2):
java -cp "./target/***-0.1-jar-with-dependencies.jar;src/clojure" jline.ConsoleRunner clojure.main run.clj
I think with tests you can use similar way.

Resources