Accessing the java executable from a cloudfoundry task command (cf run-task)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 21:09:23

In general, we consider the location of the installed JRE, as well as the command required to run the application, an internal detail subject to change without compatibility restrictions. To the best of my knowledge (running the Java Buildpack team for nearly four years) there are no contractual obligations requiring droplets to be mounted at /home/vcap either, which is why we're very careful to use $PWD in our commands.

Other early users of Java-based tasks have allowed staging to happen completely (which would ensure that things like memory calculation and JAVA_OPTS are properly placed in the command) and then use that command line without modification.

The issue you're seeing with $PWD being resolved early is one of escaping more than anything else. The first change you should probably make is to switch from double quotes (") to single quotes (') which should ensure that $ isn't resolved immediately. It's possible that somewhere else in the pipeline the environment is resolved again early possibly necessitating a \$ escape, but I'd hold off on that until you're sure that you're seeng it.

To execute a spring task I found this useful:

cf run-task vc-billing-task '$PWD/.java-buildpack/open_jdk_jre/bin/java $JAVA_OPTS -cp $PWD/. org.springframework.boot.loader.JarLauncher' --name "vc-billing-task"

Just make sure your java/build-pack is updated to your specifics

The java executable can be found here (assuming the java buildback is used):

cf run-task bignibou-batch '$PWD/.java-buildpack/open_jdk_jre/bin/java -jar bignibou-batch/build/libs/bignibou-batch.jar'

However, I am not sure this is the best way to run a java command for a task application...

P.S. Please feel free to add your own answer if you think it is better than this one.

edit: I have edited the path and replaced the hard coded app directory with the $PWD variable.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!