In one of my projects I have resources stored in /src/test/resources
(typical maven directory structure). Those resources are being used by an utility class stored in the project.
The utility class itself is being used from other projects (other projects depend on this one). I would access the resource like that:
final InputStream inputStreamDobs =
ClassLoader.class.getResourceAsStream("/dbunit/clear_db.xml");
but since I use it from different projects the path is not correct - it is relative to current project that is being built/tested
, not the one where utility class and resources are.
Any thought how to approach this?
I need to avoid absolute paths - would like to have a way of defining relative path to the utility class.
I also don't want to replicate resources over multiple projects. Cheers.
EDIT: To give a context I have a definition of tables in XML file that needs to be cleared after Integration Tests (clear whole DB schema). Integration Tests sits in multiple project, but the clear script and resource file is the same for all of them and sits in common parent project.
EDIT2:
Bonus question: I would like to access common DTD file (let's call it tables.dtd
) that need to be accessed from XML files from multiple other projects. (it will sit in common parent project).
Currently I have it duplicated over multiple project, and I refer to it from XML using directive:
<!DOCTYPE dataset SYSTEM "src/test/resources/dbunit/dobs.dtd">
How to point it to a file in different project?