0

I have a Java project in Intellij and there is a 'data' directory which hosts lots of JSON files. My Intellij has to takes a very long time to index them before I can work on the project. The reason I want to put this data directory in the project is for me to use relative path to access them. I am thinking to move this data/ directory out of the project, however that will block my project to directly access them, i.e. I have to use absolute path on a machine to read and write files to the data directory.

What's the right way to handle this situation?

user697911
  • 10,043
  • 25
  • 95
  • 169

2 Answers2

1

If you don't need to add it to the project. I recomand to declare the path as a external parameter from servlet container (tomcat context.xml) if is a web application or using a java option parameter. Or from project into a resources/config.properties file (this will need to rebuild if th path changed). To get the full path you can create an path resolver class to concatenate the rootPath parameter + your relative path.

Vasile Bors
  • 656
  • 6
  • 14
1

As was mentioned in the comments, it doesn't look like intellij supports this unless you exclude the directory. Doing so, however, doesn't mean you have to read the files from your program using an absolute path.

Assuming we are talking about a simple program initiated from the main directory:

  • In Intellij Edit the Project settings, Select "Modules", select your modules and click the Sources tab
  • Select the data directory and click the Mark as: "Excluded" button.

enter image description here

Now in the Run configuration for your app, set the working directory to your data directory (or set it to the):

enter image description here

You should now be able to access your json files from within your code using a relative path. In this example, the path would be "." (the current directory) since the working directory for your Java project is the data directory.

bclarkreston
  • 638
  • 5
  • 18