Issue
In a Maven project I want write some test results into a file in target directory of the project. Whenever, I get the project directory, it is actually getting the IntelliJ project directory instead of actual Maven directory.
Solution
I got the solution for this. Here is how I am implementing. I have my own class CSVReader which uses CSVReader library. I am writing my results in results.csv file under target directory.
URL location = CSVReader.class.getProtectionDomain().getCodeSource().getLocation();
String path = location.getFile().replace("classes/","") + "results.csv";
In the above code I am getting the target directory path and removing the classes/ by string replace method and appending my desired file name. Hope this might help someone.
Answered By - vkrams