2

I'm using IntelliJ IDEA 2020.1 CE. I have a non-Maven Java project that builds and works fine. I use the built-in build system. The resources are all correctly copied from the source resources folder to the project's output directory; however, since I use a package, e.g., org.acme, I'd like the resources to actually be copied to the output/org/acme folder, so that they end up with the .class files.

Is this possible? Do I need to perform a post-build step? Other?

Thanks, John

John Puopolo
  • 139
  • 9

1 Answers1

4

The good people at JetBrains helped me out on this one, so I thought I'd share it here.

To copy Java project resources to a directory relative to the project output directory (where the .class files go by default), use the Relative Output Path for the directory marked as your resources directory.

https://www.jetbrains.com/help/idea/content-roots.html

For example, let's suppose you have a Java project and you put your classes into a package called org.acme. Let's also assume your resources are in a resources/ directory and that your project's output directory is called target/.

What will happen by default is that your .class files will end up in target/org/acme/, but your resources will end up in target/. If you want to copy your resources to the same place as your .class files (it makes loading them easier at times), you can set your Relative Output Path to org/acme/

In the IntelliJ IDE, from the main menu:

  • File -> Project Structure
  • Select Modules from the left-hand pane
  • Select Sources from the main panel
  • Select your resources/ directory
  • Click on the pencil icon next to the resources directory
  • Add your Relative Output Path

Next time the project builds, the resources will be copied to this relative path under the primary output directory.

I hope this was useful!

John

John Puopolo
  • 139
  • 9
  • If you ever need to do the equivalent of this in Maven, or just want to understand the search process for resources better, the answer to https://stackoverflow.com/questions/61531317/how-do-i-determine-the-correct-path-for-fxml-files-css-files-images-and-other has useful information. – Some Guy Dec 31 '22 at 14:44