0

When running the app locally, it works. However, after I build a jar with maven and push it to cloud foundry, it cannot find the krb5.keytab file through the local absolute file path The krb5.keytab's path are setting in my application.yml file. e.g keytab: key: krb5.keytab file: C:\Users\Documents\WorkSpace\MyProject\kafkatool\krb5.keytab

How do I need to change the file path of krb5.keytab so when it's running on cloud foundry the app can still find the keytab?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Henry Bai
  • 367
  • 1
  • 3
  • 17

1 Answers1

1

When your Java application runs on CloudFoundry, it's running in a remote Linux container. It does not have access to your local file system and any files you reference need to be within the Linux container's filesystem, thus no c:\ Windows-style paths are going to work.

Your application, when running on CF, lives in the /home/vcap/app directory (there's also a symlink at /app which points to /home/vcap/app that you can use if you want).

In addition, your application will be executed out of the /home/vcap/app directory so the current working directory will be /home/vcap/app.

Thus, if you need to reference files you can either reference them relative to the /home/vcap/app directory or you can prefix the /home/vcap/app to all paths and use a full path to the file.


If you don't like the idea of hard-coding /home/vcap/app into your application, you can fetch this directory dynamically by looking at the HOME environment variable. When your application runs, the HOME env variable points to /home/vcap/app.

Daniel Mikusa
  • 13,716
  • 1
  • 22
  • 28
  • for the HOME environment variable. can I refer the path as {user.home}\MyProject\kafkatool\krb5.keytab? – Henry Bai Apr 27 '22 at 22:35
  • 1
    If you are in a shell, you'd need to use `$HOME`. Same if you are calling `System.getenv("HOME")` to fetch the env from Java. You can also use `System.getProperty("user.home")`, see https://stackoverflow.com/a/586345/1585136 – Daniel Mikusa Apr 28 '22 at 13:04