1

I am using Pivotal to host Spring boot app in Cloud Foundry. I am able to deploythe app without any commands fine. But my requirement is to run with an additional JVM command as a workaround for this issue

-Doracle.jdbc.timezoneAsRegion=false

Running with below manifest I get error,

---
applications:
- name: gl-bo-sample   
  command: java -jar -Doracle.jdbc.timezoneAsRegion=false
  path: ./target/backoffice-1.0-SNAPSHOT.jar
  buildpacks:
      - https://github.com/cloudfoundry/java-buildpack.git

CF Log

2019-11-29T16:33:45.606+05:30 [CELL/0] [OUT] Cell f38e366a-22ac-45ee-9dba-73e1f505525a creating container for instance e1475d2b-0c8e-4766-7e13-6da7
2019-11-29T16:33:45.952+05:30 [CELL/0] [OUT] Cell f38e366a-22ac-45ee-9dba-73e1f505525a successfully created container for instance e1475d2b-0c8e-4766-7e13-6da7
2019-11-29T16:33:46.958+05:30 [CELL/0] [OUT] Starting health monitoring of container
2019-11-29T16:33:47.168+05:30 [APP/PROC/WEB/0] [ERR] bash: java: command not found
2019-11-29T16:33:47.179+05:30 [APP/PROC/WEB/0] [OUT] Exit status 127
2019-11-29T16:33:47.182+05:30 [CELL/SSHD/0] [OUT] Exit status 0
2019-11-29T16:33:47.385+05:30 [CELL/0] [OUT] Cell f38e366a-22ac-45ee-9dba-73e1f505525a stopping instance e1475d2b-0c8e-4766-7e13-6da7
2019-11-29T16:33:47.385+05:30 [CELL/0] [OUT] Cell f38e366a-22ac-45ee-9dba-73e1f505525a destroying container for instance e1475d2b-0c8e-4766-7e13-6da7
2019-11-29T16:33:47.402+05:30 [API/2] [OUT] Process has crashed with type: "web"

Could some one tell how to achieve this or any other approach to achieve this. Thanks.

Ismail
  • 1,188
  • 13
  • 31

2 Answers2

6

OK, a few things for you.

command: java -jar -Doracle.jdbc.timezoneAsRegion=false

  1. When using the Java buildpack, don't set command unless you really, really know what you're doing. It can cause problems as you are totally overriding the command set by the Java buildpack.

  2. If you set a command, you need to make sure that you undo it. You can do this by removing it from your manifest.yml and by running cf push -c null. The -c null will tell the server side to remove the save command and go back to using what the Java buildpack decides. The other option is to cf delete your app, but that's not always possible.

  3. To set JVM arguments, you can simply cf set-env <app> JAVA_OPTS '-Doracle.jdbc.timezoneAsRegion=false, or by setting them in your manifest.yml. You can add an env: block with env variables in it.

Ex:

    ...
    env:
      JAVA_OPTS: -Doracle.jdbc.timezoneAsRegion=false
    ...

This works because the Java buildpack includes $JAVA_OPTS in the start command, so anything you put in there is substituted into the command which starts your app.

  1. If you have an executable JAR you can also use cf set-env <app> JBP_CONFIG_JAVA_MAIN '{ arguments: "--server.port=9090 --foo=bar" }' to set app arguments. This option is used to set argv arguments which get processed by the app itself, not the JVM. In the same way as JAVA_OPTS, you can set this within the env: block of your manifest.yml.

  2. For what it's worth, the reason you get bash: java: command not found is because the Java buildpack does not put java on the PATH. You need to set the full path to the java process which is at $HOME/.java-buildpack/open_jdk_jre/bin/java. So if you use the full path, you could make what you're doing above work. That said, it's strongly recommended you do not set command.

  3. Side note. Don't point buildpack to https://github.com/cloudfoundry/java-buildpack.git. You're pointing to the master branch when you do this which is a moving target. You should generally use the buildpack provided by your platform, i.e. cf buildpacks, or add a release tag to the URL like https://github.com/cloudfoundry/java-buildpack.git#v4.26 to get v4.26 of the Java buildpack.

halfer
  • 19,824
  • 17
  • 99
  • 186
Daniel Mikusa
  • 13,716
  • 1
  • 22
  • 28
  • Thanks. Your Answer totally helped in adding JVM argument. But I was not able to use a release buildpack ```https://github.com/cloudfoundry/java-buildpack.git#4.26``` in this format. Getting ```Failed to clone git repository at https://github.com/cloudfoundry/java-buildpack.git``` Could see the issue resolved in GitHub but I was not able to do it adding in Manifest. -> https://github.com/cloudfoundry/cli/issues/1232 – Ismail Dec 02 '19 at 06:12
  • That bug is quite old, check your cf cli version and make sure it's recent. I tried with `cf version 6.47.2+d526c2cb3.2019-11-05` and it worked fine. The other thing would be to confirm that your staging containers can access the Internet and download stuff, but if `https://github.com/cloudfoundry/java-buildpack.git` without the `#v4.26` works then adding the version shouldn't make a difference. They are both talking to Github. – Daniel Mikusa Dec 02 '19 at 13:42
0

You can declare it in application.properties and it should work fine.

Artur
  • 140
  • 1
  • 10
  • @Ismail Just put `oracle.jdbc.timezoneAsRegion=false` in your application.properties file instead of passing it as a JVM argument. – Artur Nov 29 '19 at 13:18