Java-src get an error java.lang.ClassNotFoundException

when I run the project I got an error java.lang.ClassNotFoundException, which is class from java-src not compiled before src clj.

Could anyone please tell me what do for this?

here’s my project.clj :

(defproject myservice "0.1.0-SNAPSHOT"
  :description "NextGen Engine"
  :url "http://myservice.com/TBE"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies
  [[org.clojure/clojure "1.8.0"]
   ;;[org.clojure/core.async "0.4.500"]
   [org.clojure/core.async "0.1.346.0-17112a-alpha"]
   [org.clojure/data.codec "0.1.0"]
   [org.clojure/data.zip "0.1.1"]
   [org.clojure/data.xml "0.0.8"]
   [org.clojure/tools.trace "0.7.9"]
   [slingshot "0.12.2"]
   [prismatic/schema "1.1.3"]
   [clj-time "0.13.0"]
   [cheshire "5.7.0"]
   [com.fasterxml.jackson.core/jackson-core "2.8.6"]
   [com.fasterxml.jackson.dataformat/jackson-dataformat-xml "2.8.6"]
   [com.fasterxml.jackson.module/jackson-module-jaxb-annotations "2.5.3"]
   [com.taoensso/timbre "4.10.0"]
   [com.taoensso/nippy "2.13.0"]
   [com.taoensso/encore "2.90.1"]
   [com.taoensso/carmine "2.16.0"]
   [circleci/clj-keyczar "0.1.3"]
   [ring/ring-core "1.3.2"]
   [ring/ring-jetty-adapter "1.3.2"]
   [ring/ring-devel "1.3.2"]
   [ring/ring-servlet "1.3.2"]
   [ring/ring-json "0.3.1"]
   
   [compojure "1.6.0"]
   [liberator "0.15.1"]
   [http-kit "2.4.0"]
   [clj-http "3.10.3"]
   [hickory "0.7.0"]
   [instaparse "1.4.1"]
   [com.google.guava/guava "18.0"]
   [org.apache.pdfbox/pdfbox "1.8.9"]
   [com.draines/postal "2.0.4"]
   [org.clojure/tools.nrepl "0.2.12"]
   [com.github.kyleburton/clj-xpath "1.4.11"]
   [org.apache.ws.security/wss4j "1.6.19"]

   [xalan "2.7.2"]
   [clj-pdf "2.1.0"
    :exclusions [xalan]]

   [aleph "0.4.6"]  
   [environ "1.0.0"]
   [org.clojure/data.csv "0.1.2"]


   ;; DBMS SQL QUERY
   [mysql/mysql-connector-java "5.1.6"]
   [org.clojure/java.jdbc "0.7.5"]
   [korma "0.4.3"]

   ;; TEMPLATE HTML
   [selmer "1.11.7"]

   [org.bouncycastle/bcprov-jdk15on "1.59"
    :exclusions [bctsp-jdk14 bcprov-jdk14 bcmail-jdk14]]]

  :java-source-paths ["src-java"]

  :plugins [[cider/cider-nrepl "0.15.1"]
            [lein-pprint "1.1.1"]
            [lein-environ "1.0.0"]]

  :repositories {"project" "file:repo"}

  :main xbe.core
  :source-paths ["src"]

  :profiles {:dev
             {:source-paths ["dev"]
              :dependencies []
              :env {:http-port 9090
                    :http-port-websvc 9094
                    :repl-port 9092}
              :jvm-opts
              ["-Xmx2g" "-Xms1g" "-Xss512k"
               "-Djava.awt.headless=true"
               "-Dcom.sun.management.jmxremote.port=9091"]}
             :devxml
             {:source-paths ["dev"]
              :dependencies []
              :env {:http-port 9090
                    :http-port-websvc 9094
                    :repl-port 9092
                    :disable-gds-registration true}
              :jvm-opts
              ["-Xmx2g" "-Xms1g" "-Xss512k"
               "-Djava.awt.headless=true"
               "-Dcom.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true"
               "-Dcom.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump=true"
               "-Dcom.sun.xml.ws.transport.http.HttpAdapter.dump=true"
               "-Dcom.sun.xml.internal.ws.transport.http.HttpAdapter.dump=true"
               "-Dcom.sun.xml.internal.ws.transport.http.HttpAdapter.dumpTreshold=1048576"
               "-Dcom.sun.management.jmxremote.port=9091"]}
             :live
             {:prep-tasks ["javac" "compile"]
              :dependencies []
              :env {:http-port 7080
                    :http-port-websvc 7084
                    :repl-port 7082
                    :live? true}
              :jvm-opts
              ["-Xmx12g" "-Xms2g"
               "-Dcom.sun.management.jmxremote.port=8081"]}}
  
  :jvm-opts 
  ["-Dcom.sun.management.jmxremote"
   "-Dcom.sun.management.jmxremote.ssl=false"
   "-Dcom.sun.management.jmxremote.authenticate=false"
   "-Djava.net.preferIPv4Stack=true"
   "-Dclojure.compiler.direct-linking=true"]
  )

Thanks,
Isaac Omy

paste full error log please?

java.lang.ExceptionInInitializerError

at clojure.main.<clinit>(main.java:20)

Caused by: java.lang.ClassNotFoundException: myservice.SoapHandler, compiling:(myservice/soaphandler.clj:1:1)

at clojure.lang.Compiler.load(Compiler.java:7391)

at clojure.lang.RT.loadResourceScript(RT.java:372)

at clojure.lang.RT.loadResourceScript(RT.java:363)

at clojure.lang.RT.load(RT.java:453)

at clojure.lang.RT.load(RT.java:419)

at clojure.core$load$fn__5677.invoke(core.clj:5893)

at clojure.core$load.invokeStatic(core.clj:5892)

at clojure.core$load.doInvoke(core.clj:5876)

at clojure.lang.RestFn.invoke(RestFn.java:408)

at clojure.core$load_one.invokeStatic(core.clj:5697)

at clojure.core$load_one.invoke(core.clj:5692)

at clojure.core$load_lib$fn__5626.invoke(core.clj:5737)

at clojure.core$load_lib.invokeStatic(core.clj:5736)

at clojure.core$load_lib.doInvoke(core.clj:5717)

at clojure.lang.RestFn.applyTo(RestFn.java:142)

at clojure.core$apply.invokeStatic(core.clj:648)

at clojure.core$load_libs.invokeStatic(core.clj:5774)

at clojure.core$load_libs.doInvoke(core.clj:5758)

at clojure.lang.RestFn.applyTo(RestFn.java:137)

at clojure.core$apply.invokeStatic(core.clj:648)

at clojure.core$require.invokeStatic(core.clj:5796)

at myservice.SoapHandler$eval52888$loading__5569__auto____52889.invoke(soaphandler.clj:1)

at myservice.SoapHandler$eval52888.invokeStatic(ndc.clj:1)

at myservice.SoapHandler$eval52888.invoke(ndc.clj:1)

at clojure.lang.Compiler.eval(Compiler.java:6927)

at clojure.lang.Compiler.eval(Compiler.java:6916)

at clojure.lang.Compiler.load(Compiler.java:7379)

at clojure.lang.RT.loadResourceScript(RT.java:372)

at clojure.lang.RT.loadResourceScript(RT.java:363)

at clojure.lang.RT.load(RT.java:453)

at clojure.lang.RT.load(RT.java:419)

at clojure.core$load$fn__5677.invoke(core.clj:5893)

at clojure.core$load.invokeStatic(core.clj:5892)

at clojure.core$load.doInvoke(core.clj:5876)

at clojure.lang.RestFn.invoke(RestFn.java:408)

at clojure.core$load_one.invokeStatic(core.clj:5697)

at clojure.core$load_one.invoke(core.clj:5692)

at clojure.core$load_lib$fn__5626.invoke(core.clj:5737)

at clojure.core$load_lib.invokeStatic(core.clj:5736)

at clojure.core$load_lib.doInvoke(core.clj:5717)

at clojure.lang.RestFn.applyTo(RestFn.java:142)

at clojure.core$apply.invokeStatic(core.clj:648)

at clojure.core$load_libs.invokeStatic(core.clj:5778)

at clojure.core$load_libs.doInvoke(core.clj:5758)

at clojure.lang.RestFn.applyTo(RestFn.java:137)

at clojure.core$apply.invokeStatic(core.clj:648)

at clojure.core$require.invokeStatic(core.clj:5796)

at clojure.lang.Compiler.eval(Compiler.java:6927)

at clojure.lang.Compiler.eval(Compiler.java:6916)

at clojure.lang.Compiler.load(Compiler.java:7379)

at clojure.lang.RT.loadResourceScript(RT.java:372)

at clojure.lang.RT.loadResourceScript(RT.java:363)

at clojure.lang.RT.load(RT.java:453)

at clojure.lang.RT.load(RT.java:419)

at clojure.core$load$fn__5677.invoke(core.clj:5893)

at clojure.core$load.invokeStatic(core.clj:5892)

at clojure.core$load.doInvoke(core.clj:5876)

at clojure.lang.RestFn.invoke(RestFn.java:408)

at clojure.core$load_one.invokeStatic(core.clj:5697)

at clojure.core$load_one.invoke(core.clj:5692)

at clojure.core$load_lib$fn__5626.invoke(core.clj:5737)

at clojure.core$load_lib.invokeStatic(core.clj:5736)

at clojure.core$load_lib.doInvoke(core.clj:5717)

at clojure.lang.RestFn.applyTo(RestFn.java:142)

at clojure.core$apply.invokeStatic(core.clj:648)

at clojure.core$load_libs.invokeStatic(core.clj:5778)

at clojure.core$load_libs.doInvoke(core.clj:5758)

at clojure.lang.RestFn.applyTo(RestFn.java:137)

at clojure.core$apply.invokeStatic(core.clj:648)

at clojure.core$require.invokeStatic(core.clj:5796)

at user$eval3$loading__5569__auto____4.invoke(user.clj:1)

at user$eval3.invokeStatic(user.clj:1)

at user$eval3.invoke(user.clj:1)

at clojure.lang.Compiler.eval(Compiler.java:6927)

at clojure.lang.Compiler.eval(Compiler.java:6916)

at clojure.lang.Compiler.load(Compiler.java:7379)

at clojure.lang.RT.loadResourceScript(RT.java:372)

at clojure.lang.RT.loadResourceScript(RT.java:359)

at clojure.lang.RT.maybeLoadResourceScript(RT.java:355)

at clojure.lang.RT.doInit(RT.java:475)

at clojure.lang.RT.<clinit>(RT.java:331)

... 1 more

Caused by: java.lang.ClassNotFoundException: myservice.SoapHandler

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

at clojure.lang.DynamicClassLoader.findClass(DynamicClassLoader.java:69)

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

at clojure.lang.DynamicClassLoader.loadClass(DynamicClassLoader.java:77)

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

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

at java.lang.Class.forName(Class.java:348)

at clojure.lang.RT.classForName(RT.java:2168)

at clojure.lang.RT.classForNameNonLoading(RT.java:2181)

at clojure.lang.Compiler.eval(Compiler.java:6927)

at clojure.lang.Compiler.eval(Compiler.java:6916)

at clojure.lang.Compiler.load(Compiler.java:7379)

... 84 more

but when I run the project with comment the import declaration and then the java class already build on target dir,

After that I rerun with uncomment the import declaration the project running perfectly

Did you run lein javac to compile the Java source code?

when I run lein javac still got same error java.lang.ClassNotFoundException

Is there a minimum repo you can share that exhibits the problem?

The compiler can’t manage to find this file:
myservice/soaphandler.clj
So it might be related to the namespace of this file and the namespace when you tryibg to get it from dependencies.

Make sure that the namespace is set correctly.

To check further post here the line when you get this file in the dependencies, the namespace from this file it self and the name that you gave to this file.

I have check the name space is correct,
when I comment import declaration (to java-src class) on clj file and run the project with lein run,
the project run perfectly but when almost finish compile all file in project
I check on console say:
“Compiling 3 source files to target/classes”
and then the project recompile all file again and then running.
after that I stop running the project

I check the target/classes my java class there, then I uncomment import declaration and lein run the project running perfectly

so its like when I first run the java-src not compiled yet so my clj file with import declaration couldn’t found the java class from java-src.

I dont have the project too complex :sweat_smile:

I haven’t used lein in a few years but maybe lein compile first invokes the javac task and that’s why your java class is compiled and available. As @seancorfield mentioned you will have to run lein javac before you do lein run. You can also try lein do javac, run.

If that doesn’t work, a small example repo would go a long way in helping sort this out even if it is a simple project… maybe it’s just a workflow issue.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.