Classpath issue when using multi module project

Hello all,

I'm using a multi module project. I have one project, with multiple modules, which each have their own output path. Now, I have a JUnit test, say in project A, which uses test files from project B. However, when running the test, the 'Edit Configurations' window only allows me to pick the classpath of project A (needed for the classfiles), OR the classpath of project B (needed for the resources).

My question is: how can I make this configuration work? I was hoping to be able to use the project as a classpath, but, since this is not an option, what should I do?

You can easy reproduce this, by making a multiproject with 2 modules, module A and B, and add a the following class file to project A, and a file called file.txt to project B. If someone can print anything other than null, please let me know!

Comment actions Permalink

A solution would be creating a third module, without any source
or content roots defined and make this module depend on all other
modules in the project. Now if you specify this particular module for
the run configuration it will join all the classpathes of the modules in
the project.


Comment actions Permalink

Well, if module A is using files contained in module B, then module A depends on module B, right? So then just add this dependency to your setup and use the classpath from module A in your run configuration.

Or does module B contains resources only used for tests and you don't want to have this dependency of module A on module B? Then you should move your test class from module A to module B and make module B dependent on module A.

Comment actions Permalink

Thanks for the answer. I thought the modules were already depending on each other, but I was mistaken in this. Adding the module dependency did the trick! Thanks again!



Please sign in to leave a comment.