Search code examples
javaeclipseherokuspark-framework

File paths for java spark project deployed into Heroku


I have deployed a java spark app onto Heroku but seem to be getting errors such as:

2017-02-16T22:17:35.519937+00:00 app[web.1]: java.io.FileNotFoundException: src/main/resources/csvs/webApp/questions/questions.csv (No such file or directory)

I can't seem to locate my files. When I run the project locally in Eclipse (on windows), all is working well. What about the file paths do i need to change for the app to find the files when it is live. Sample code of the working local code:

String directory = "src/main/resources/csvs/webApp/questions/";
BufferedReader questions = null;
String line;
ArrayList<String> questionList = new ArrayList<String>();

try {
    questions = new BufferedReader(new FileReader(directory + "questions.csv"));

    while ((line = questions.readLine()) != null) {
        if(!(line.equals("Question"))) {
            questionList.add(line);   
        }
    }

} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

Thanks for the help.


Solution

  • The heroku deploy:war and heroku deploy:jar commands do not upload your src/ directory by default (the only uploads your WAR or JAR file respectively).

    You can add the --includes src option to the heroku deploy:* commands.