0
votes

New to cloud foundry, using the java buildpack to push a zip distribution of a java app. It detects the start script correctly, but when the start script gets to the point where it needs to start up the jvm, I get this error:

bash: java: command not found

Apparently 'java' is not on the shell's path during execution of the script, and I'm not finding a JAVA_HOME definition anywhere.

What is the path to use for starting java apps? Where is it documented?

FALSE ALARM

Many thanks to @DanielMikusa for pointing out that JAVA_HOME is indeed set, even in the pretty old version of the buildpack that was in use. Nothing to see here.

EDIT #1

I've been able to find out that when the start script launches there is a jre located in $PWD/.buildpack-java/oracle_jre. But, this can't be what I'm expected to use to specify for the path of JAVA_HOME, can it? It seems like this location is entirely dependent on the java buildpack's current implementation. It seems like either the jre's bin folder should be in the start script's process' path or that there should be an environment variable or other configuration established prior to running the launch script so I can use that value for finding the java executable.

EDIT #2

Below is the output during the cf push operation:

PS E:\dev\hoobajoob\myproject\build\distributions> cf push -p .\my-service-1.0.0.zip my-service
Using manifest file E:\dev\hoobajoob\myproject\build\distributions\manifest.yml

Creating app my-service in org DEV / space dev as [email protected]...
OK

Creating route my-service.cflab.dctmlabs.com...
OK

Binding my-service.cflab.dctmlabs.com to my-service...
OK

Uploading my-service...
Uploading app files from: C:\Users\hoobajoob\AppData\Local\Temp\unzipped-app384867239
Uploading 9.7M, 9390 files
Done uploading
OK

Starting app my-service in org DEV / space dev as [email protected]...
Downloading oracle_buildpack_151...
Downloading binary_buildpack...
Downloading go_buildpack...
Downloading python_buildpack...
Downloading java-buildpack-offline-v3-19-2...
Downloaded java-buildpack-offline-v3-19-2
Downloading java-buildpack-offline-4-7...
...<more downloads>

Creating container
Successfully created container
Downloading app package...
Downloaded app package (53.1M)
Staging...
-----> Java Buildpack Version: v3.5.1 (offline) | https://github.com/cloudfoundry/java-buildpack.git#3abc3db
-----> Downloading Oracle JRE 1.8.0_112 from http://127.0.0.1/oracle-jre/trusty/x86_64/jre-8u112-linux-x64.tar.gz (found
 in cache)
       Expanding Oracle JRE to .java-buildpack/oracle_jre (2.3s)
-----> Downloading Open JDK Like Memory Calculator 2.0.1_RELEASE from https://download.run.pivotal.io/memory-calculator/
trusty/x86_64/memory-calculator-2.0.1_RELEASE.tar.gz (found in cache)
       Memory Settings: -Xms2304M -XX:MetaspaceSize=314572K -Xss1M -Xmx2304M -XX:MaxMetaspaceSize=314572K
-----> Downloading Spring Auto Reconfiguration 1.10.0_RELEASE from https://download.run.pivotal.io/auto-reconfiguration/
auto-reconfiguration-1.10.0_RELEASE.jar (found in cache)
Exit status 0
Staging complete
Uploading droplet, build artifacts cache...
Uploading droplet...
Uploading build artifacts cache...
Uploaded build artifacts cache (108B)
Uploaded droplet (120.5M)
Uploading complete
Destroying container
Successfully destroyed container

0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
1 of 1 instances running

App started


OK
App my-service was started using this command `CALCULATED_MEMORY=$($PWD/.java-buildpack/oracle_jre/bin/java-buildpack-memory-calculator-2.0.1_RELEASE -memorySizes=metaspace:64m.. -memoryWeights=heap:75,metaspace:10,native:10,stack:5 -memoryInitials=heap:100%,metaspace:100% -totMemory=$MEMORY_LIMIT) &&  JAVA_HOME=$PWD/.java-buildpack/oracle_jre JAVA_OPTS="-Djava.io.tmpdir=$TMPDIR -XX:OnOutOfMemoryError=$PWD/.java-buildpack/oracle_jre/bin/killjava.sh $CALCULATED_MEMORY" exec $PWD/my-service-1.0.0/bin/launch`
1
Java apps should be packaged as jar or war archives and pushed to cloud foundry. Not as zip file. - K.AJ
That is not the only way java apps can be packaged. See: github.com/cloudfoundry/java-buildpack/blob/master/docs/… - Hoobajoob
using the java buildpack to push a zip distribution of a java app Are you deploying a java buildpack or a java app? - K.AJ
If you want to upload/replace a buildpack, follow this - docs.cloudfoundry.org/adminguide/buildpacks.html - K.AJ
@Hoobajoob - Not sure I follow you here. I see JAVA_HOME being set in the command: JAVA_HOME=$PWD/.java-buildpack/oracle_jre. Or did you manually set the start command? - Daniel Mikusa

1 Answers

0
votes

Writing up the comments above in case someone else comes across this question.

  1. We reviewed the full output of staging and the start up command generated by the Java buildpack.
  2. We could see from the start command generated by the Java buildpack that it is the start commands responsibility to set JAVA_HOME.
  3. If you rely on the Java buildpack to create the start command for your dist-zip style applications, it will "do the right thing" and add the JAVA_HOME environment variable with the correct path to the start command.
  4. If you need to create a custom start command, it is your responsibility to set JAVA_HOME correctly.
  5. If you cf ssh into an application started by the Java buildpack, it is your responsibility to set JAVA_HOME.