开发者

How to Run a jar file which contains clojure and java code compiled class files. java file contains main method

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开发者_C百科.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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜