4

I'm a migrating user from Eclipse to IntelliJ.

Most of my projects contain a resource folder in the root of the project, which now in this case is a module:

enter image description here .

The fonts folder in the above directory is used by the code to load in fonts for use by the rendering. The problem is that in IntelliJ, the compilation target is the project folder itself, so the fonts aren't detected. You can get past this by manually editing the run configuration so that the working directory is in the module root.

My question is, can I somehow change IntelliJ to have this behavior by default for every project instead of having to manually do it every time? As in, by default, the target working directory for programs is always the root folder of the module the class is from.

Thanks in advance!

Anonymous
  • 696
  • 8
  • 21
  • You won't have a default working directory with a packaged application anyway--you need to be loading from the classpath using `getResourceAsStream` or equivalent. – chrylis -cautiouslyoptimistic- May 20 '19 at 00:45
  • Packaging resources with massive filesizes into the JAR itself is usually a bad practice, considering if just that file needs to be updated, you'd have to update the entire package to do so. – Anonymous May 20 '19 at 00:56

1 Answers1

1

The problem is that in IntelliJ, the compilation target is the project folder itself

When building project/module, the IDE includes into compile classpath all files/sources from the folders which are marked as source/resource/generated source/test source etc type.

Also note that for the case of a Maven (Gradle) projects IDE takes configuration, including compiler configuration, from the Maven pom.xml files. By default Maven will not process (copy) resource files from the directory with sources. You need to explicitly configure it in pom.xml or move the resource files into folder that will be of a resource type.

Now about the main question:

...manually editing the run configuration so that the working directory is in the module root.

My question is, can I somehow change IntelliJ to have this behavior by default for every project instead of having to manually do it every time?

You can change the Run/Debug Configuration template

Community
  • 1
  • 1
Andrey
  • 15,144
  • 25
  • 91
  • 187