2

This is a pretty simple question but I can't work it out so I hope you'll bear with me. I'm running IntelliJ on Windows and I'm using it as a Clojure IDE. I'm trying to invoke my core.clj by running RT.loadResourceScript but I cannot figure out the correct path for my core.clj. I'm new to IntelliJ, having worked with Leiningen on Linux before this.

The project is under C:\Users\L\IdeaProjects\LearningClojure The core.clj and Driver.java files are located in the src folder.

I have tried using "src/core.clj" "core.clj" "src\core.clj" and variations going as far up the tree as "LearningClojure" for my CLJ variable.

My Driver.java file is as follows

import clojure.lang.RT;
public class Driver
{
private static final String CLJ = "src/core.clj";
public static void main( String[] args)
{
    try
    {
        RT.loadResourceScript(CLJ);
        RT.var("learning", "main").invoke(args);
    }
    catch(Exception E)
    {
        E.printStackTrace();
    }
    finally
    {
        System.out.println("End of Execution");
    }
}

}

Output returns

End of Execution
java.io.FileNotFoundException: Could not locate Clojure resource on classpath: src/core.clj
at clojure.lang.RT.loadResourceScript(RT.java:366)
at clojure.lang.RT.loadResourceScript(RT.java:346)
at clojure.lang.RT.loadResourceScript(RT.java:338)
at Driver.main(Driver.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Process finished with exit code 0

On a somewhat related note does anyone have a link to a good explanation of Java packages and how they correspond to classpaths and directory layouts when dealing with IDE project layouts?

LiamRyan
  • 1,892
  • 4
  • 32
  • 61
  • Check [this answer](http://stackoverflow.com/a/11177224/104891). – CrazyCoder Jan 25 '13 at 15:50
  • Thanks but I must be missing something, I'm looking for the "base" directory from which IntelliJ gets its files. I would have thought that the path "core.clj" would have worked as core.clj and Driver.java are both in the src folder – LiamRyan Jan 25 '13 at 16:06
  • You need to ensure that `core.clj` is copied to the module compiler output, when loading `src/` is not needed, `CLJ = "core.clj";` should work. – CrazyCoder Jan 25 '13 at 16:19
  • Thanks for replying once again, my resource pattern does contain .clj currently as I'm using LaClojure (!?*.java;!?*.form;!?*.class;!?*.groovy;!?*.scala;!?*.flex;!?*.kt;!?*.clj) and I'm still seeing the same issue. Any ideas or have I missed the point you are making? – LiamRyan Jan 25 '13 at 16:32
  • 1
    The pattern excludes `*.clj` files from being copied to the output (classpath), most likely it's the cause of the problem, remove `!` before `?*.clj`. – CrazyCoder Jan 25 '13 at 16:38
  • Perfect, thanks for your patience with this. I had assumed that it was correct as LaClojure was installed. I'll create an answer summarizing the issue. – LiamRyan Jan 25 '13 at 16:43

2 Answers2

3

By default source files are not copied to the output (classpath), with LaClojure plug-in installed *.clj is considered source.

Your use case if very specific and requires source files to appear in the classpath, therefore you have to adjust Settings | Compiler | Resource Patterns to include (or not to exclude) *.clj files.

You also don't need to prefix the path with src/.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
0

As you can see in the comments from CrazyCoder the issue here is that IntelliJ IDEA needs to copy the necessary files to the module compiler output. This applies to all files.

File -> Settings -> Compiler (highlight compiler, do not expand with the +)

In my IntelliJ IDEA the Resource Pattern showed

!?*.java;!?*.form;!?*.class;!?*.groovy;!?*.scala;!?*.flex;!?*.kt;!?*.clj 

which I assumed to be correct, however the ! means that the file IS NOT copied. In the case of a .clj file I needed to remove the !. For any other type of files you need to add it using the following syntax:

";*.extension"     
Irene
  • 744
  • 1
  • 12
  • 36
LiamRyan
  • 1,892
  • 4
  • 32
  • 61