0

I am trying to deploy Springboot java application into PCF, We have 2-3 files which our application needs at run time like cert file. I have those files under resources folder but getting error file not found exception.

Can anyone suggest me where can i keep the files so that it gets dump into /var/home/app dir in PCF or do i need to create some env so that app will know where to read the files.

  • How are you reading the cert file? Are you including the `classpath:` prefix? – Eduardo Bueno Jan 11 '22 at 18:11
  • Run `jar tf ` and confirm that your files are actually being included in the JAR file you are pushing. When you `cf push -p my/file.jar` the contents of the JAR file will end up at `/home/vcap/app` (or `/app` which is a symlink) (not `/var/home/app`). So if it's in the JAR, the file should be there & accessible with the right path. – Daniel Mikusa Jan 12 '22 at 01:46

1 Answers1

0

Maybe you can put those files on

src/main/java/webapp/folder/file.extension

Then, in your code something like this:

import javax.servlet.ServletContext;

@Autowired
ServletContext servletContext;

static final String SEPARATOR = File.separator;
static final String REALPATH = SEPARATOR + "folder" + SEPARATOR + "file.extension";

String path = servletContext.getRealPath(REALPATH);

So, you can pass the path wherever you want to.

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • There are several caveats to using a webapp folder with Spring Boot, see https://stackoverflow.com/questions/28725635/spring-boot-configure-it-to-find-the-webapp-folder. If you adjust as described on that thread and do use the webapp folder that would make the files downloadable, which is probably not desired/could be a security leak). Just keep this in mind when bundling files in the JAR/WAR. – Daniel Mikusa Jan 12 '22 at 01:56