I have two projects: A and B. Project B has a maven plugin, and when this is executed it should take some templates, which are resources of project A.
The templates are located in C:/path/to/project/A/module1/src/main/resources/templates.
The method that retrieves these templates uses velocity engine and the method is in a class located in C:/path/to/project/A/module1/src/main/java. I use the following path for the templates:
String path = new File( "" ).getAbsolutePath() + File.separator + "src" + File.separator + "main" + File.separator + "resources" + File.separator + "templates" + File.separator;
In my unit tests this path is equal to C:/path/to/project/A/module1/src/main/resources/templates, but when I run the maven plugin from Project B, this path is equal to C:/path/to/project/B/module1/src/main/resources/templates. I realize this is because I launch from project B. I know if I put my templates in project B that it works but that's not what I want.
What I would like to achieve is to let the path always be equal to C:/path/to/project/A/module1/src/main/resources/templates. However, since other people are also using this project and their path to project A is most likely different from mine I cannot just do
String path = "C:/path/to/project/A/module1/src/main/resources/templates".
So I would like to keep the first part in such a way that the path to project A is found, followed by "src/main/resources/templates". Is this possible and if yes, how?
EDIT To clarify: what I want is to get the path to project A from a method A1 that is inside project A. And this path to project A should also be found when I run method A1 from project B. The problem that I have with how I am retrieving the path right now is that when I run method A1 from project B then I get the path to project B.
SOLUTION It is working when I use the ClasspathResourceLoader (instead of the FileResourceLoader).
new File(""). + .. + .. +thing can be simplified tonew File("src/main/resources/templates")- Java can deal with a/separator even if running on Windows