0

I'm trying to deploy a .jar file in Heroku using the maven plugin. I have two files in src/main/resources folder read using the File class in the program. I'm able to access them when executing the jar file normally but when deployed to Heroku, I can't figure where they are stored. Running jar tf <filename>.jar gives the two files to not be in a folder. What's the path to the two files when deployed to Heroku?

Loading BG
  • 131
  • 2
  • 9

2 Answers2

1

You're looking for Class#getResource or Class#getResourceAsStream. It will give you access to files in your packaged JAR file as either an URL or InputStream.

InputStream is = getClass().getResourceAsStream("/data.json");

A similar question has been asked and answered here.

Malax
  • 9,436
  • 9
  • 48
  • 64
0

i use this code in my project when it need add some files in target directory

<build>
    <resource>
    <directory>./src/main/resources</directory> 
        <targetPath>./</targetPath>
    </resource> 
    <resource> 
    <!-- mkdir -->
    <directory>./filestorage</directory>
    <targetPath>../filestorage</targetPath>
    </resource>
<build>