开发者

FileNotFoundException when making a jar file from the clojure file

I am trying to go through the process of creating a jar file from a simple clojure file. Below is my clojure code:

(ns app.first (:gen-class))  
(refer 'clojure.core)  
(defn -main [& args] (println "this program worked!"))  

I am using these instructions to create the jar file: http://en.wikibooks.org/wiki/Clojure_Programming/Tutorials_and_Tips

I see the err开发者_运维百科or "java.io.FileNotFoundException: Could not locate app/hello__init.class or app/hello.clj on classpath: (NO_SOURCE_FILE:0)" when I try to complete the (compile 'app.first) step.

The only difference between my attempt and the link is the name of my file (first.clj instead of hello.clj).

Can anyone see where I am going wrong? Or for that matter, all I want to do is learn how to create a jar from a clojure file, so if anyone knows of a better/easier way to do that, let me know.


It's better to use Leiningen for such tasks - it allows to maintain dependencies, and packs all necessary components into jar file


I'm rusty on this, but I heard about other people with similar problems.

I think it's helpful to remember that the classpath you indicate points to the root of your class tree, and package names end up creating subdirectories within that tree. Awkwardly stated, but I hope you get the idea. Thus, I think you need to do some kind of gymnastics with creating directories to match the "app.first" -> "/app/first" hierarchy.

Sorry, that's as close as I come to a sensible and useful answer. Hope this helps you.


EDIT:

The Prime Directive of Computer Science: It only works if you do everything right! I spent almost 10 minutes fiddling with this but was finally successful.

Here's what I needed to do to get your program to compile:

  • created a directory app, and within that, first.clj with your code.
  • checked for the *compile-path* by doing (pr *compile-path) within Clojure. It said "classes".
  • created a second directory classes parallel to app.
  • in the shell, did export CLASSPATH=.:./classes
  • in Clojure, did (compile 'app.first)

... and I found a bunch of class files in classes. JARring those should be a snap.

I found it very helpful to run (doc compile) because that reminded me of the requirement to have a directory to satisfy the requirement for a *compile-path*.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜