alexander-yakushev / lein-skummet

Leiningen plugin for lean-compiling Clojure projects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

having difficulty getting main class to find/load

tewarfel opened this issue · comments

I have a project "client" with multiple dependencies. I've tried substituting in the org.skummet/clojure for org.clojure/clojure, but am getting
"Error: Could not find or load main class client.core"
when I type "lein skummet run"

If I change the org.skummet/clojure line back to org.clojure/clojure, "lein run" runs.

here's my project.clj:

(defproject client "0.1.0-SNAPSHOT"
  :description "Demo client for inpainting"
  :dependencies [
                 [org.skummet/clojure "1.7.0-r1"]
                ; [org.clojure/clojure "1.7.0"]
                 [org.clojure/tools.logging "0.3.1"]
                 [seesaw "1.4.5"]
                 [me.raynes/fs "1.4.6"]
                 [clj-time "0.11.0"]
                 [clj-http "2.0.0"]
                 [com.damballa/abracad "0.4.12"]
                 [net.mikera/imagez "0.8.0"]
                 [slingshot "0.12.2"]
                 [org.slf4j/slf4j-simple "1.7.12"] ; our copy in ../local_maven_repository
                 [stemcs/schemas "0.1.0"] ; our copy in ../local_maven_repository
                 [stemcs/common "0.1.0"]
                 [clj-stacktrace "0.2.0"]
                 [org.clojure/core.async "0.1.346.0-17112a-alpha"]
                 ]
  :exclusions [[org.clojure/clojure]]
  :plugins [
            [lein-bin "0.3.4"]
            [org.skummet/lein-skummet "0.2.2"]
            [lein-localrepo "0.5.3"]]
  :source-paths ["src"]
  :repositories {"localMavenRepository" ~(str (.toURI (java.io.File. "../local_maven_repository")))}
  :test-paths ["test" ]
  :resource-paths ["resources"]
  :jar-exclusions [#".svn" #".git" #".DS_Store"]
  :main client.core
  :aot :all
  :bin {:name "client"
        :bin-path "."
        :bootclasspath true}
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all}
             :default []})

When I do

lein skummet run

I get

Error: Could not find or load main class client.core

I also get the same results with the sample project included. If I try

lein skummet jar

I get the error:

Warning: The Main-Class specified does not exist within the jar. It may not be executable as expected. A gen-class directive may be missing in the namespace which contains the main method.

However, if I do

lein skummet compile
lein skummet jar

it WILL build the uberjar correctly (best I can tell), and the uberjar is then executable with java -jar

So, it looks like there's something not getting passed or read when just doing

lein skummet run

Hello Tom.

run does not imply compile, you have to execute them separately and explicitly.

Hi Alexander,
Thank you for taking the time to answer my question (and for the work you put into skummet / pumpet – I look forward to trying them out).

What is the correct sequence to build/execute a skummet-compiled clojure program without making an uberjar first (or do you always have to make an uberjar)?

If I just type lein skummet compile it completes.
If I type lein skummet run immediately afterward I still get the message Error: Could not find or load main class

If I then type lein skummet jar, I can execute the resultant uberjar with java -jar target/lein-skummet-sample-0.0.1-SNAPSHOT-standalone.jar
and it will execute correctly, giving me:

Hello, World! 42

foobar

I cannot figure out how to get lein skummet run to work by itself, though, and am confused because the behavior seems different from regular clojure lein run.

-Tom

This is strange. lein do skummet compile, skummet run should execute the main file. Can you check if the class client.core is present in target/classes/ directory after you run lein skummet compile? Thanks.

Here’s the same result using the sample included with the git repo – there is a core.class, but not a sample.core.

WE26998:sample warf949$ ls

project.clj resources src target test

WE26998:sample warf949$ ls target

classes stale

WE26998:sample warf949$ ls target/classes

META-INF sample

WE26998:sample warf949$ ls target/classes/sample

core$_main.class core$foo.class core$wont_be_lean.class core__init.class

core$fn__4117.class core$loading__1495__auto____4115.class core.class

WE26998:sample warf949$ ls src

sample

WE26998:sample warf949$ ls src/sample

core.clj

WE26998:sample warf949$ more src/sample/core.clj

(ns sample.core

;; (:require [clojure.core.async :as a])

(:gen-class))

(defn wont-be-lean []

(str "foo" "bar"))

(defn foo

"I don't do a whole lot."

[x]

(println "Hello, World!" x)

(println (wont-be-lean))

;; (let [c (a/chan)]

;; (a/put! c x)

;; (a/go (println "Ultimate answer is" (a/<! c))))

)

(defn -main [& args]

(foo (or (first args) 42)))

I went ahead and instrumented the lein-skummet plugin to show the dependencies line – doing lein run I get:

WE26998:sample warf949$ lein skummet run

deps line is /Volumes/Samsung_2TB/skummet-test/lein-skummet/sample/target/classes:/Users/warf949/.m2/repository/org/skummet/clojure/1.7.0-r1/clojure-1.7.0-r1.jar:/Users/warf949/.m2/repository/org/clojure/core.async/0.1.346.0-17112a-alpha/core.async-0.1.346.0-17112a-alpha.jar:/Users/warf949/.m2/repository/org/clojure/tools.analyzer.jvm/0.1.0-beta12/tools.analyzer.jvm-0.1.0-beta12.jar:/Users/warf949/.m2/repository/org/clojure/tools.analyzer/0.1.0-beta12/tools.analyzer-0.1.0-beta12.jar:/Users/warf949/.m2/repository/org/clojure/core.memoize/0.5.6/core.memoize-0.5.6.jar:/Users/warf949/.m2/repository/org/clojure/core.cache/0.6.3/core.cache-0.6.3.jar:/Users/warf949/.m2/repository/org/clojure/data.priority-map/0.0.2/data.priority-map-0.0.2.jar:/Users/warf949/.m2/repository/org/ow2/asm/asm-all/4.1/asm-all-4.1.jar

:main is sample.core

Error: Could not find or load main class

Anything else to try?

-Tom

From: Alexander Yakushev <notifications@github.commailto:notifications@github.com>
Reply-To: alexander-yakushev/lein-skummet <reply@reply.github.commailto:reply@reply.github.com>
Date: Friday, October 9, 2015 at 11:40 AM
To: alexander-yakushev/lein-skummet <lein-skummet@noreply.github.commailto:lein-skummet@noreply.github.com>
Cc: "Warfel, Thomas E" <Thomas.Warfel@pnnl.govmailto:Thomas.Warfel@pnnl.gov>
Subject: Re: [lein-skummet] having difficulty getting main class to find/load (#7)

This is strange. lein do skummet compile, skummet run should execute the main file. Can you check if the class client.core is present in target/classes/ directory after you run lein skummet compile? Thanks.


Reply to this email directly or view it on GitHubhttps://github.com//issues/7#issuecomment-146957586.

OK, so there is a main file (target/classes/sample/core.class = sample.core). I've just downloaded the sample again, did lein skummet compile, then lein skummet run and it worked. But for some reason that file is not seen.

Which version of Leiningen do you use? Mine is 2.5.1.

WE26998:sample warf949$ lein version

Leiningen 2.5.3 on Java 1.8.0_60 Java HotSpot(TM) 64-Bit Server VM

From: Alexander Yakushev <notifications@github.commailto:notifications@github.com>
Reply-To: alexander-yakushev/lein-skummet <reply@reply.github.commailto:reply@reply.github.com>
Date: Friday, October 9, 2015 at 12:08 PM
To: alexander-yakushev/lein-skummet <lein-skummet@noreply.github.commailto:lein-skummet@noreply.github.com>
Cc: "Warfel, Thomas E" <Thomas.Warfel@pnnl.govmailto:Thomas.Warfel@pnnl.gov>
Subject: Re: [lein-skummet] having difficulty getting main class to find/load (#7)

OK, so there is a main file (target/classes/sample/core.class = sample.core). I've just downloaded the sample again, did lein skummet compile, then lein skummet run and it worked.

Which version of Leiningen do you use? Mine is 2.5.1.


Reply to this email directly or view it on GitHubhttps://github.com//issues/7#issuecomment-146963446.

I've updated to 2.5.3 and it still works for me. Can you try executing the following:

java -cp ~/.m2/repository/org/skummet/clojure/1.7.0-RC3-r1/clojure-1.7.0-RC3-r1.jar:target/classes sample.core

By the way, thanks for staying with me on this:).

Likewise, thanks for your support; I am interested in trying this out.
I will need to go pick up my kids shortly, though, and may have to wait until later this evening to go much further…

I think we’re close. That line gave an error, but a slight change that worked:

WE26998:sample warf949$ java -cp ~/.m2/repository/org/skummet/clojure/1.7.0-RC3-r1/clojure-1.7.0-RC3-r1.jar:target/classes sample.core

Error: A JNI error has occurred, please check your installation and try again

Exception in thread "main" java.lang.NoClassDefFoundError: clojure/lang/IFn

at java.lang.Class.getDeclaredMethods0(Native Method)

at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)

at java.lang.Class.privateGetMethodRecursive(Class.java:3048)

at java.lang.Class.getMethod0(Class.java:3018)

at java.lang.Class.getMethod(Class.java:1784)

at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)

at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)

Caused by: java.lang.ClassNotFoundException: clojure.lang.IFn

at java.net.URLClassLoader.findClass(URLClassLoader.java:381)

at java.lang.ClassLoader.loadClass(ClassLoader.java:424)

at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)

at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

... 7 more

WE26998:sample warf949$ ls ~/.m2/repository/org/skummet/clojure

1.7.0-r1

WE26998:sample warf949$ java -cp ~/.m2/repository/org/skummet/clojure/1.7.0-r1/clojure-1.7.0-r1.jar:target/classes sample.core

Hello, World! 42

foobar

-Tom

From: Alexander Yakushev <notifications@github.commailto:notifications@github.com>
Reply-To: alexander-yakushev/lein-skummet <reply@reply.github.commailto:reply@reply.github.com>
Date: Friday, October 9, 2015 at 12:24 PM
To: alexander-yakushev/lein-skummet <lein-skummet@noreply.github.commailto:lein-skummet@noreply.github.com>
Cc: "Warfel, Thomas E" <Thomas.Warfel@pnnl.govmailto:Thomas.Warfel@pnnl.gov>
Subject: Re: [lein-skummet] having difficulty getting main class to find/load (#7)

I've updated to 2.5.3 and it still works for me. Can you try executing the following:

java -cp ~/.m2/repository/org/skummet/clojure/1.7.0-RC3-r1/clojure-1.7.0-RC3-r1.jar:target/classes sample.core

By the way, thanks for staying with me on this:).


Reply to this email directly or view it on GitHubhttps://github.com//issues/7#issuecomment-146966402.

All right, so you are using the latest Skummet version, although it doesn't matter. That java call is exactly what lein skummet run is supposed to do. I've got no idea why it doesn't.

I added some debugging to lein skummet 0.2.3-SNAPSHOT. Please switch to that version and do DEBUG=1 lein skummet run, then inspect what it says in the output.

Suit yourself, we can continue when you have time.

Borrowing a fresh machine from my wife back at home, it seems like the sample file is still referencing the other version, but it does compile and run using that older version.

phreadq2:test audrey$ git clone https://github.com/alexander-yakushev/lein-skummet.git
Cloning into 'lein-skummet'...
remote: Counting objects: 61, done.
remote: Total 61 (delta 0), reused 0 (delta 0), pack-reused 61
Unpacking objects: 100% (61/61), done.
Checking connectivity... done.
phreadq2:test audrey$ ls
lein-skummet
phreadq2:test audrey$ cd lein-skummet
phreadq2:lein-skummet audrey$ ls
project.clj sample      src
phreadq2:lein-skummet audrey$ lein install
Created /Volumes/Boot+OS/Users/audrey/test/lein-skummet/target/lein-skummet-0.2.3-SNAPSHOT.jar
Wrote /Volumes/Boot+OS/Users/audrey/test/lein-skummet/pom.xml
Installed jar and pom into local repo.
phreadq2:lein-skummet audrey$ cd sample
phreadq2:sample audrey$ ls
project.clj src
phreadq2:sample audrey$ lein skummet compile
Retrieving org/skummet/lein-skummet/0.2.2/lein-skummet-0.2.2.pom from clojars
Retrieving org/skummet/lein-skummet/0.2.2/lein-skummet-0.2.2.jar from clojars
Retrieving org/skummet/clojure/1.7.0-r1/clojure-1.7.0-r1.pom from clojars
Retrieving org/clojure/core.async/0.1.346.0-17112a-alpha/core.async-0.1.346.0-17112a-alpha.pom from central
Retrieving org/clojure/core.async/0.1.346.0-17112a-alpha/core.async-0.1.346.0-17112a-alpha.jar from central
Retrieving org/skummet/clojure/1.7.0-r1/clojure-1.7.0-r1.jar from clojars
Compiling sample.core
phreadq2:sample audrey$ lein skummet run
Hello, World! 42
foobar

Now editing the sample to use the newer version and deleting the old from the repository:

phreadq2:sample audrey$ ls ~/.m2/repository/org/skummet
clojure     lein-skummet
phreadq2:sample audrey$ ls ~/.m2/repository/org/skummet/lein-skummet
0.2.2               0.2.3-SNAPSHOT          maven-metadata-local.xml
phreadq2:sample audrey$ rm -rf ~/.m2/repository/org/skummet/lein-skummet/0.2.2
phreadq2:sample audrey$ vi project.clj
phreadq2:sample audrey$ more project.clj
(defproject lein-skummet-sample "0.0.1-SNAPSHOT"
  :dependencies [[org.skummet/clojure "1.7.0-r1"]
                 [org.clojure/core.async "0.1.346.0-17112a-alpha"]]
  :exclusions [org.clojure/clojure]
  :profiles {:default []}
  :plugins [[org.skummet/lein-skummet "0.2.3-SNAPSHOT"]]
  :main sample.core
  :aot :all
  :skummet-skip-vars ["#'leantest.core/wont-be-lean"])
phreadq2:sample audrey$ lein clean
phreadq2:sample audrey$ lein skummet compile
Compiling sample.core
phreadq2:sample audrey$ lein skummet run
Hello, World! 42
foobar
phreadq2:sample audrey$ ls
project.clj resources   src     target      test
phreadq2:sample audrey$ rm -rf target
phreadq2:sample audrey$ lein skummet compile
Compiling sample.core
phreadq2:sample audrey$ lein skummet run
Hello, World! 42
foobar
phreadq2:sample audrey$ DEBUG=1 lein skummet run
Leiningen's classpath: /Volumes/Boot+OS/Users/audrey/.lein/self-installs/leiningen-2.5.3-standalone.jar
Applying task skummet to [run]
Running java -cp /Volumes/Boot+OS/Users/audrey/test/lein-skummet/sample/target/classes:/Volumes/Boot+OS/Users/audrey/.m2/repository/org/skummet/clojure/1.7.0-r1/clojure-1.7.0-r1.jar:/Volumes/Boot+OS/Users/audrey/.m2/repository/org/clojure/core.async/0.1.346.0-17112a-alpha/core.async-0.1.346.0-17112a-alpha.jar:/Volumes/Boot+OS/Users/audrey/.m2/repository/org/clojure/tools.analyzer.jvm/0.1.0-beta12/tools.analyzer.jvm-0.1.0-beta12.jar:/Volumes/Boot+OS/Users/audrey/.m2/repository/org/clojure/tools.analyzer/0.1.0-beta12/tools.analyzer-0.1.0-beta12.jar:/Volumes/Boot+OS/Users/audrey/.m2/repository/org/clojure/core.memoize/0.5.6/core.memoize-0.5.6.jar:/Volumes/Boot+OS/Users/audrey/.m2/repository/org/clojure/core.cache/0.6.3/core.cache-0.6.3.jar:/Volumes/Boot+OS/Users/audrey/.m2/repository/org/clojure/data.priority-map/0.0.2/data.priority-map-0.0.2.jar:/Volumes/Boot+OS/Users/audrey/.m2/repository/org/ow2/asm/asm-all/4.1/asm-all-4.1.jar sample.core nil
Hello, World! 42
foobar

...and this one works too. I'm a bit confused and slightly embarrassed, but it seems like its working fine on this machine.

I'll try again on my machine at work on Monday when I'm back and see what happens there.
Thanks for your help with this; I'll let you know what I find out.
-Tom

You are welcome, Tom. I suppose it has to be something very specific that prevents the plugin working correctly on your machine. Maybe wrong file permissions or something. Please keep me updated.

Today I deleted everything in my ~/.m2/repository/org/skummet/* directories, deleted the old lein-skummet directory, downloaded the current lein-skummet from github, did a "lein install" on it, then went into the sample directory, updated the sample project.clj from "0.2.2" to "0.2.3-SNAPSHOT", then did "lein skummet compile" (okay), and "lein skummet run". And this time it works here too! With debug=1, I get:

WE26998:sample warf949$ DEBUG=1 lein skummet run
Leiningen's classpath: /Users/warf949/.lein/self-installs/leiningen-2.5.3-standalone.jar
Applying task skummet to [run]
Running java -cp /Volumes/Samsung_2TB/skummet-test/lein-skummet/sample/target/classes:/Users/warf949/.m2/repository/org/skummet/clojure/1.7.0-r1/clojure-1.7.0-r1.jar:/Users/warf949/.m2/repository/org/clojure/core.async/0.1.346.0-17112a-alpha/core.async-0.1.346.0-17112a-alpha.jar:/Users/warf949/.m2/repository/org/clojure/tools.analyzer.jvm/0.1.0-beta12/tools.analyzer.jvm-0.1.0-beta12.jar:/Users/warf949/.m2/repository/org/clojure/tools.analyzer/0.1.0-beta12/tools.analyzer-0.1.0-beta12.jar:/Users/warf949/.m2/repository/org/clojure/core.memoize/0.5.6/core.memoize-0.5.6.jar:/Users/warf949/.m2/repository/org/clojure/core.cache/0.6.3/core.cache-0.6.3.jar:/Users/warf949/.m2/repository/org/clojure/data.priority-map/0.0.2/data.priority-map-0.0.2.jar:/Users/warf949/.m2/repository/org/ow2/asm/asm-all/4.1/asm-all-4.1.jar sample.core nil
Hello, World! 42
foobar

I apologize for the hassle, and thank you for your patience. I don't know what my original issue was, but at this point it seems to be working.

No problem Tom! Let's consider it fixed.