简体   繁体   中英

Cloud Foundry : How to deploy spring boot app with an additional JVM command

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.

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.

  4. 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 .

  5. 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 .

  6. 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, ie 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.

Hope that helps!

您可以在 application.properties 中声明它,它应该可以正常工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM