luminus icon indicating copy to clipboard operation
luminus copied to clipboard

java.lang.ClassNotFoundException error when project has java source files

Open insaneparachute opened this issue 9 years ago • 7 comments

I created a basic luminus app using

lein new luminus myapp

and added

:java-source-paths ["src/java"] in project.clj file

and added a simple java file src/java/com/example/Hello.java

package com.example;

public class Hello
{

    public static String getFoo()
    {
        return "foo";
    }

}

In src/clj/myapp/routes/home.clj, I'm referencing this function getFoo()

When I run lein javac

It gives me an error

java.lang.ClassNotFoundException: com.example.Hello

insaneparachute avatar Nov 10 '16 18:11 insaneparachute

That seems correct, but not sure why it's not compiling in your case. I have a similar setup here, and it compiles fine using both lein javac and in Cursive.

yogthos avatar Nov 10 '16 22:11 yogthos

@insaneparachute @yogthos I encountered this same problem A project created with lein new luminus chess +auth +swagger +cljs What I discovered is that if you delete the :profiles key and its value then lein javac curiously works fine. Full details at http://stackoverflow.com/questions/40824115/lein-javac-tries-to-compile-clojure-code-and-fails I would also like to know how to fix this

ccherng avatar Nov 27 '16 02:11 ccherng

Hi, I've been able to get around this problem by using the DEBUG mode on lein (DEBUG=true lein javac), copying the /tmp/.leiningen-cmdlineXXXX.tmp file created by lein into the root directory of the app and running a javac using the parameters in the tmp file.

Is this the correct way to go about this or is there a better way to do this, @yogthos ?

insaneparachute avatar Mar 14 '17 18:03 insaneparachute

@insaneparachute @yogthos , I think I run into the same issue. The project is generated using +site. I'm able to make the uberjar work by adding :prep-tasks ["javac" "compile" ["cljsbuild" "once" "min"]] into the uberjar profile. However the dev profile for command lein repl still doesn't work. I'm resorting to temporarily remove java code references from (ns .. calls to start a repl, then adding the java references back would work. But those are not fun to do.

lsyoyo avatar Mar 11 '19 02:03 lsyoyo

I was able to make a minimal project to reproduce the issue I see. https://github.com/lsyoyo/test-repl-error, clone and run lein repl to see the error.

lsyoyo avatar Mar 11 '19 17:03 lsyoyo

After some digging, I found this issue - https://github.com/luminus-framework/luminus-template/issues/319, and it might be helpful for whoever gets here.

lsyoyo avatar Mar 12 '19 01:03 lsyoyo

So, the problem was that the user namespace was trying to load code before it was compiled then?

yogthos avatar Mar 12 '19 17:03 yogthos