Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java classes can't be resolved - not a relative path - IllegalArgumentException #2624

Open
loeschzwerg opened this issue Dec 7, 2021 · 1 comment

Comments

@loeschzwerg
Copy link

loeschzwerg commented Dec 7, 2021

I get this error, whenever I try to start a Clojure REPL* within cursive.

  • (nrepl, run with leiningen, working directory: full path to project)
java.lang.IllegalArgumentException: /export/src/xxx/file/util/MyException.class is not a relative path
	at clojure.java.io$as_relative_path.invokeStatic(io.clj:414)
	at clojure.java.io$file.invokeStatic(io.clj:426)
	at clojure.java.io$file.invoke(io.clj:418)
	at cursive.leiningen.task$prep_hook$fn__2418$fn__2425.invoke(task.clj:40)

I added a custom Exception to use as a break exception.

package xxx.file.util;

public class MyException extends Exception {
}
export
+ src.xxx
+- file
+-- util
+--- MyException.class
+-- writer.clj
+- ...
+ project.clj

adjusted the project.clj

  :java-source-paths [ "src/de/xxx/file/util"]

and added the Exception to be used

(ns xxx.file.writer
  (:require [...]
  (:import xxx.file.util.MyException)))

(loop [[item port] (alts! [data-chan timeout-chan ex-chan])]
        (cond
          (= port data-chan)    (when item
                                  (item-fn item)
                                  (recur (alts! [data-chan timeout-chan ex-chan])))
          (= port timeout-chan) (throw (TimeoutException.))
          (= port ex-chan)      (throw (MyException.)))))

1f9fc63a-5764-11ec-9800-1831bf08bfc7 (reference for stack-trace report)

When I try to do lein repl in the CLI it works just fine.
Currently I use "Run with IntelliJ project Classpath" instead of "Run with Leiningen", which also works.

Could you kindly advise how to resolve this error or classify it as a bug?

@d-t-w
Copy link

d-t-w commented Mar 31, 2022

Hi @cursive-ide @loeschzwerg I can add some detail to this one - I was having the same issue and somewhat strangely it came down to the path itself. It appears that some source paths triggered the "Not a relative path" error.

We build our product for both Java8 and Java11. We have some Java source that is specific to either version, then we have some source that is applicable to either.

A very simplified version of our project.clj looks like:

{
  :java-source-paths ["src-java"]
  :profiles {
              :java-8-base   {:java-source-paths ["src-java-8"]}
              :java-11-base  {:java-source-paths ["src-java-11"]}
  }
}

I found:

  • Starting a REPL with +java-8-base worked fine
  • Starting a REPL with +java-11-base failed with the error 'not a relative path'

Given that one profile worked, and I isolated all the other possible differences (there's not much else other than some different versions of the Jetty library and slightly different imports in the Java source code), I came to the conclusion that it must be the actual path name causing an issue.

I changed

{:java-source-paths ["src-java-11"]}

to

{:java-source-paths ["src-java-x"]}

And it just worked.

In the end I went with

{:java-source-paths ["src-java11"]}

Which was also fine. So somehow the difference between "src-java-11" and ("src-java-x" or "src-java11") was causing this error to occur for me.

Colin: when I have a moment i'm fairly sure I can provide a reproducer for you if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants