0

I have two separate maven projects in which my first project is executing the code and generating some data that data I am writing into a file and this file should be created in Project2 under src/test/java/feature folder location.

**Project1**

public class Dependency {

public void execute() throws MojoExecutionException, MojoFailureException {
    
    System.out.println(".... execution begins...."); 
    GenerateData ob=new GenerateData();
    ob.getData();
    String fileLoc="./src/test/java/feature";(location of src/test/java/feature of Proj2 is          `given here)`
    File file=new File(fileLoc + ".feature");
    file.createNewFile();
}

**Project2**

src/test/java
 -feature

Is there a way that I can give the directory path of src/test/java/feature folder of Project2 in Project1 so that my file would get created in Project2.

8
  • You can either add the absolute path to Project 1 if you don't plan to share the program on to other systems nor change folder locations (brittle but quick and easy approach) or you can look into file finding tutorials if you do plan on having it on other systems. Commented Aug 3, 2020 at 16:23
  • I suppose another way would be to have Project 1 use a File Browser so you can manually tell it where to put the file initially and then save that location into a local file inside Project 1 if you want it to just remember your original selection. Not sure how flexible of a approach you're looking for. Commented Aug 3, 2020 at 16:33
  • no folder location wont change ...it would be the same src/test/java/feature everytime and created file would go inside feature folder only. But how shall i give absolute path of a folder which is in another project like in my case src/test/java/feature Commented Aug 3, 2020 at 16:34
  • Quick and dirty approach would be to open the folder in File Explorer, use the bar at the top to copy the absolute file path, and then paste it into a String in your program then just use that String as your file write location. Commented Aug 3, 2020 at 16:36
  • 1
    The idiomatic way would be to add "Project 1" as dependency with scope test to "Project 2" and pull your feature file from that dependency. Generating into some other projects src/ folder is IMHO "working against the tools" Commented Aug 3, 2020 at 16:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.