Reputation: 1524
java -cp clojure.jar clojure.main compile.clj this is compiling the clojure code. javac CalculateSum.java compiling java code. jar cvf sum.jar *.class getting jar file of class files.
java CalculateSum is running main and giving output correctly. How to run jar file from java environment? like java -cp clojure.jar;sum.jar clojure.main CalculateSum where CalculateSum is main class.
sample code _utils.clj_
(ns utils
(:gen-class :name Utils
:methods [#^{:static true} [sum [java.util.Collection] long]]))
(defn sumx [coll] (reduce + coll))
(defn -sum [coll] (sumx coll))
compile.clj
(set! *compile-path* "./")
(compile 'utils)
CalculateSum.java
public class CalculateSum {
public static void main(String[] args) {
java.util.List<Integer> xs = new java.util.ArrayList<Integer>();
xs.add(10);
xs.add(5);
System.out.println(Utils.sum(xs));
}
}
Aim is to craete jar file out of this code. and run jar file
java should call clojure code, execute it and print result
Upvotes: 0
Views: 543
Reputation: 1500185
Okay, so there are two things:
To run it just from a jar file rather than making it an executable jar file, you should be fine with just:
java -cp sum.jar CalculateSum
or possibly (if it needs classes from closure.jar at execution time)
java -cp closure.jar;sum.jar CalculateSum
To turn it into an executable jar file which you can run with
java -jar sum.jar
you'll need a manifest file including a Main-Class attribute letting you set the entry point, and possibly a Class-Path attribute to add the closure.jar file to the jar's classpath.
Follow the links for more details.
Upvotes: 1