Hi Rob, Thanks for your helpful reply. I have finally had success.
On Dec 20, 7:10 pm, Rob Wolfe <r...@smsnet.pl> wrote: > Are you really sure that function `copy-to-jar` looks exactly like this: > ... > I mean `unix-path` function is called twice not only once. Evidently not. So I started from fresh again, just to be certain. > In order to see what is exactly the problem you need to comment out > `try-except` clause in core.clj in "-main" function. This wasn't necessary in the end, in my case. >> E:\keep\clojure\helloworld>E:\etc\clojure\Leiningen\lein.py new >> Wrong number of arguments to task new. > >And this message is totally OK. "new" command requires at least one >argument, e.g. project name: lein.py new test_proj My mistake, sorry. (I should have remembered that new requires 2 args from before.) >Anyway I came up with this not very elegant soultion: ># part of lein.py ><code> >def run_leiningen(argv): >... I added your amended code to the python script to handle a second argument. Aside: if anyone cuts and pastes Rob's python code from a browser, you may have to delete the whitespace after the 6 continuation symbols (\) or else python (V2.6) complains. So I have got past yesterday's issues and now have a standalone jar file. In case, it is helpful to others, the commands that I used (virtually the same as in your last email) were: E:\etc\clojure\Leiningen\lein.py clean E:\etc\clojure\Leiningen\lein.py deps E:\etc\clojure\Leiningen\lein.py compile E:\etc\clojure\Leiningen\lein.py jar E:\etc\clojure\Leiningen\lein.py uberjar :: WARNING: Not 'java -jar helloworld.jar'. D'oh! java -jar helloworld-standalone.jar Thanks for your time with this. Regards, John. On Dec 20, 7:10 pm, Rob Wolfe <r...@smsnet.pl> wrote: > John <john.b.ga...@gmail.com> writes: > > Hi Rob, > > > I made the changes src/leiningen/jar.clj that you suggested. > > Then issued the commands: > > > E:\etc\clojure\Leiningen\lein.py clean > > E:\etc\clojure\Leiningen\lein.py deps > > E:\etc\clojure\Leiningen\lein.py compile > > E:\etc\clojure\Leiningen\lein.py jar > > E:\etc\clojure\Leiningen\lein.py uberjar > > > and they all work to compile the new Leiningen. > > (Fyi, I originally didn’t have the 'lein.py deps' step > > and this seems to be essential, in my case.) > > > Then in the python script (lein.py), I set > > > LEIN_JAR = expanduser("E:/keep/eclipse/3.5/git-leiningen/src/ > > leiningen-standalone.jar") > > CLOJURE_JAR = expanduser("E:/keep/eclipse/3.5/git-leiningen/src/lib/ > > clojure-1.1.0-master-20091218.160125-7.jar") > > > i.e. to point at the newly compiled leiningen and the version of > > clojure > > that it downloaded into its 'lib' folder. > > > I then tried the simple example at > >http://zef.me/2470/building-clojure-projects-with-leiningen > > using this project.clj > > > (defproject helloworld "0.1" > > :dependencies [[org.clojure/clojure "1.1.0-master-SNAPSHOT"] > > [org.clojure/clojure-contrib "1.0-SNAPSHOT"]] > > :main helloworld) > > > to correspond to the project.clj in E:/keep/eclipse/3.5/git-leiningen/ > > src > > which contains > > > (defproject leiningen "1.1.0-SNAPSHOT" > > :description "A build tool designed not to set your hair on fire." > > :url "http://github.com/technomancy/leiningen" > > :dependencies [[org.clojure/clojure "1.1.0-master-SNAPSHOT"] > > [org.clojure/clojure-contrib "1.0-SNAPSHOT"] > > [ant/ant-launcher "1.6.2"] > > [jline "0.9.94"] > > [org.apache.maven/maven-ant-tasks "2.0.10"]] > > :dev-dependencies [[leiningen/lein-swank "1.0.0-SNAPSHOT"]] > > :main leiningen.core) > > > I am able to compile the helloworld example: > > > E:\keep\clojure\helloworld>E:\etc\clojure\Leiningen\lein.py compile > > [copy] Copying 2 files to E:\keep\clojure\helloworld\lib > > Compiling helloworld > > > But 'lein.py uberjar' or 'lein.py jar' both produce stange errors: > > > E:\keep\clojure\helloworld>E:\etc\clojure\Leiningen\lein.py uberjar > > Wrong number of arguments to task uberjar. > > E:\keep\clojure\helloworld>E:\etc\clojure\Leiningen\lein.py jar > > Wrong number of arguments to task jar. > > Are you really sure that function `copy-to-jar` looks exactly like this: > > <code> > (defmethod copy-to-jar :path [project jar-os spec] > (doseq [child (file-seq (file (:path spec)))] > (when-not (.isDirectory child) > (let [path (unix-path (str child)) > path (re-sub (re-pattern (str "^" (unix-path (:root project)))) > "" path) > path (re-sub #"^/resources" "" path) > path (re-sub #"^/classes" "" path) > path (re-sub #"^/src" "" path) > path (re-sub #"^/" "" path)] > (.putNextEntry jar-os (JarEntry. path)) > (copy child jar-os))))) > </codec> > > I mean `unix-path` function is called twice not only once. > > In order to see what is exactly the problem you need to comment out > `try-except` clause in core.clj in "-main" function. > > > > > and so does 'lein.py new' > > > E:\keep\clojure\helloworld>E:\etc\clojure\Leiningen\lein.py new > > Wrong number of arguments to task new. > > And this message is totally OK. "new" command requires at least one > argument, e.g. project name: > lein.py new test_proj > But see below. > > > E:\keep\clojure\helloworld>E:\etc\clojure\Leiningen\lein.py version > > Leiningen nil on Java 1.6.0_18-ea Java HotSpot(TM) Client VM > > > This seems to be a different issue (possibly with the lein.py > > script?). > > Any pointers would be very welcome. > > But there is still problem with passing arguments from windows > command line to leiningen. All arguments are considered as one > by Leiningen, so: > lein.py "new" "test_proj" > means for Leiningen: > lein.py "new test_proj" > > I'm starting to think that it would be > nice to call leiningen as regular jar (I mean adding leiningen.clj > with "-main" function). Using "clojure.main" and "-e" is really > difficult on Windows. > @Phil what do you think about it? > > Anyway I came up with this not very elegant soultion: > > # part of lein.py > <code> > def run_leiningen(argv): > def escape_arg(s): > return s.replace("\\", "\\\\").replace("\"", "\\\"") > > ARGS = ['"' + escape_arg(s) + '"' for s in argv] > CMD = ("java -Xbootclasspath/a:%s -client -cp %s clojure.main" \ > + " -e \"(use 'leiningen.core) (-main \\\"%s\\\")\"") \ > % (quote_cp([CLOJURE_JAR]), quote_cp(CLASSPATH), ARGS[0]) > > if len(ARGS) == 2: > CMD = ("java -Xbootclasspath/a:%s -client -cp %s clojure.main" \ > + " -e \"(use 'leiningen.core) (-main \\\"%s\\\" > \\\"%s\\\")\"") \ > % (quote_cp([CLOJURE_JAR]), quote_cp(CLASSPATH), ARGS[0], > ARGS[1]) > > elif len(ARGS) == 3: > CMD = ("java -Xbootclasspath/a:%s -client -cp %s clojure.main" \ > + " -e \"(use 'leiningen.core) (-main \\\"%s\\\" \\\"%s\\\" > \\\"%s\\\")\"") \ > % (quote_cp([CLOJURE_JAR]), quote_cp(CLASSPATH), > ARGS[0], ARGS[1], ARGS[2]) > system(CMD) > </code> > > I hope there is no command which requires more than 2 arguments. ;) > > And now I managed to do what you were trying: > > c:\src\clojure\test>c:\tools\bin\lein.py new test_proj > Created new project in: test_proj > > c:\src\clojure\test>dir test_proj > 2009-12-20 19:29 <DIR> . > 2009-12-20 19:29 <DIR> .. > 2009-12-20 19:29 56 .gitignore > 2009-12-20 19:29 173 project.clj > 2009-12-20 19:29 119 README > 2009-12-20 19:29 <DIR> src > 2009-12-20 19:29 <DIR> test > > C:\src\clojure\test\helloworld>dir > 2009-12-20 19:31 <DIR> . > 2009-12-20 19:31 <DIR> .. > 2009-12-20 19:05 187 project.clj > 2009-12-20 19:06 <DIR> src > > C:\src\clojure\test\helloworld>c:\tools\bin\lein.py compile > [copy] Copying 2 files to C:\src\clojure\test\helloworld\lib > Compiling helloworld > > C:\src\clojure\test\helloworld>c:\tools\bin\lein.py jar > > C:\src\clojure\test\helloworld>c:\tools\bin\lein.py uberjar > Including helloworld.jar > Including clojure-1.1.0-master-20091218.160125-7.jar > Including clojure-contrib-1.0-20091212.214557-33.jar > > C:\src\clojure\test\helloworld>dir > 2009-12-20 19:33 <DIR> . > 2009-12-20 19:33 <DIR> .. > 2009-12-20 19:32 <DIR> classes > 2009-12-20 19:33 5 261 247 helloworld-standalone.jar > 2009-12-20 19:33 5 498 helloworld.jar > 2009-12-20 19:32 <DIR> lib > 2009-12-20 19:05 187 project.clj > 2009-12-20 19:06 <DIR> src > > HTH, > Rob -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en