Adding property files to classpath

Sorry, if this is a simple and obvious quesiton, but I am stumped. I have 2 modules in my project. The web module needs to have property files (.conf, .htm & .properties) from the other on the classpath in order to work. How can I add property files to the classpath from an external module? I feel like I have tried every solution i could find on Stackoverlfow and nothing seems to be working.

Thanks for your help!

Comment actions Permalink


A typical way is the following. Let's you have web module W and another module R. Then:
1. Make sure resources are copied into the compiler output path: Settings / ... / Compiler / Resource patterns.
2. Add R to the module dependencies of W.
3. Check the Project Structure dialog / Artifacts / the W web artifact, make sure R compiler output is included.

Is that acceptable?


Comment actions Permalink

In my situtaiton the module is not a web module, but a regular java application. I did add the Velocity template extention to the compiler resource patterns. (*.htm).
The 2nd module with the properties I need looks something like this.

----properties ( properties I need)
----CDE ( properties I need)


If I need the properties & CDE directory on the classpath for MyRegularJavaApp; So I go to module settings for MyRegularJavaApp and go to the dependecies tab. I'll add the path to properties and CDE as a "classes" dependency. But, this doesn't seem to work - when I run the tests from the app I get resouce not found as it is looking for a file from CDE.

Am I setting things up incorrectly?

Thanks for your time!

Comment actions Permalink

> In my situtaiton the module is not a web module, but a regular java application.

So you just want this application to run from the IDE, and not creating a deployable artifact like JAR or WAR? Ok.

> I'll add the path to properties and CDE as a "classes" dependency.

This may work with some conditions, but it's rather exotic configuration. If you are not sure what you're doing, remove that paths. Instead, add Module Dependency (it is called so in the GUI) from MyRegularJavaApp to BatchConfig on the same dialog page. If necessary see:


Comment actions Permalink

I am not sure if this is the correct way, but this is how I got it to work.

I added the path to my (external) property files to the dependencies tab as mentioned. When I run the application (not tests) the applicaiton picks up the properties from the external module. In order to get the test cases to run for this application I had to add a new content root. The new content root pointed to the directory of those external sources; I then marked it as "test sources". Now, I am able to run my tests and run the application! yay!

Initailly, I was adding the external module property files to the dependancies, but trying to run the test caes so it was failing. Apparently, I need them in both places for this to work; seems a bit odd to me. Using STS I add them to the classpath and I can run the application and test cases. Not sure why I need to fiddle with extra steps here.

If I have the setup wrong please let me know. I'd like to be sure I am setting things up correctly.

Thanks for your help and time.

Comment actions Permalink

Your steps _seem_ to be superfluous to me, because a) the most typical relationship between modules in IDEA is a module dependency, and you still do not create it (your dependency to a path is not a module dependency), b) you say you have to perform some extra steps, while most users have not to do it. So it _looks_ like something exotic, but I do not see your project, maybe there is no other way.

To make the story shorter, you can:
1) attach your zipped project here (of course, if it's not a secret), so I will look and say what to do,
2) take a look on attached picture: it shows how the module dependeny looks like, and how is it created.

Again, it's just a way all people do it, but maybe your project really has some specific.



Comment actions Permalink

Hey Alexander:

I realize attaching the project would make this easier, but unfortunately I am unable to do that. Maybe the projects here are "exotic", but I tried what you suggested and the application errors out since it is unable to find the appropriate property files. In my case my applicaiton needs to have 2 specific directories (velocity templates .htm and .properties files) from an external module on the class path; not the entire module. When I select "Jars or directories" from the modules dependencies tab, then navigate and add the directories I need, I am able to run the application. But, adding the entire module doesn't help as I get exceptions telling me the application can't find the property files.

Thanks for your help.


Please sign in to leave a comment.