Adding Resource Files to Run Configuration

I have seen this question in the forums and on several Google Searches, but following the suggestions has so far been unsuccessful.

I have a module in a project with the following Configuration

       ... various libraries

I need to add the, .bindings and resource files into my module classpath so I can execute the JMSConnector.main() and access the file like this:


I have already gone to the ModuleSettings -> Sources   and added the cfg folder under Source Folders (I was told this would put the folder and it's files in the classpath).   I have gone to the Settings -> Compiler area and checked that ?*.properties was in there and put in the .bindings pattern.

My run configuration has com.whatever.jms.JMSConnector as the running class.

When I execute it with this configuration, it cannot find the "" file.   (However, if I move the file in the same package as JMSConnector, it sees it....

BUT, I do not want to have to place my resources (which may be accessed by several different classes) into the folder with EACH CLASS.

Any help.... (I am moving from Eclipse where this was consistent and easy to do to IntelliJ -- bought a licence for it.).

Stephen McConnell


Interesting. I wonder how Eclipse allows the configuration to copy to multiple different package output folders (clazz.getResourceAsStream("") will only pick it up if it is the same package as the clazz).

I really usually just put the file in the package where they are needed. You could recreate the same package structure underneath your cfg folder is you want to have them in a separate root folder.

If you really need to access the from multiple classes, then I think it best if you load them from the default package by adding a leading slash clazz.getResourceAsStream("/")

Otherwise the only other option that comes to my mind is let IDEA automatically run an ant target / maven goal after compilation that "manually" copies the resource files to the folders where you want them (right click an ant target in the toolwindow and select "Execute On...").


It should just work(TM) in Idea too...

First, when my app doesn't find files I always verify (explorer or shell) that the files _are_ actually copied into the output directory.

Depending on whether they are/are not copied in the output directory, I know who to blame: Idea or the problem beween chair and keyboard :)


Thanks for the quick replies.   I seriously was wondering if the problem existed between the chair and the keyboard ;) .

Eclipse handles creating a resource folder by allowing you to put that resource folder directly in the classpath.  I was under the impression that doing the Module Settings -> Sources thing and setting the "cfg" folder under the source root allowed you to do that also.   In my execution of applications, I make sure that my startup script puts the configuration folder in the classpath and this method always works (It has for the past 5 years).  But switching over to a new IDE takes some learning of the particulars of the IDE.

Again, I need to acces the properties files from multiple classes.  This is why one creates a resource folder.  One then has a single point of change when one changes the properties files and one doesn't have to recompile or rebuild the entire project when you change them (which would be the solution you have to do if you put them in the "package" that the class is in.

Any more suggestions why one cannot add a resource folder to the run configuration classpath?

Stephen McConnell


Fixed it....

First, thanks to Carlos AND Stephen (not me)  for pointing me in the right direction.   The file, log4j and .bindings files were indeed being copied to the output folders under the /classes folder.   Good news.

Now, for the PEBCAK part of it...   I needed to have the file path in my Load Properties method point to  "/"... the "/" was the thing (Like Stephen Fredrick said)....  since they were in the classes folder, I had to point out that they were in the "root" of the classes folder...

The program now picks up the file and the bindings file correctly.

As I said, each IDE has it's own quirks.  Once one figures them out, then IntelliJ's increase in productivity will become more and more apparent.

Thanks for all the help.

Stephen McConnell
"Boredom is a personal defect"
-- Lamar Stephens


Please sign in to leave a comment.