cloudfoundry / java-buildpack

Cloud Foundry buildpack for running Java applications
Apache License 2.0
437 stars 2.58k forks source link

JBP_CONFIG_JAVA_MAIN not honoured for a Spring boot application #307

Closed shahid21st closed 8 years ago

shahid21st commented 8 years ago

I am trying to deploy and run this on PWS - https://github.com/paulc4/microservices-demo. This is actually a fat jar containing 4 spring boot applications. The instructions for running locally for an application named registration is:

java -jar target/microservice-demo-1.1.0.RELEASE.jar registration

I am trying to do the same, by deploying the whole app, but wanted to run the registration app. As per https://github.com/cloudfoundry/java-buildpack#configuration-and-extension and https://github.com/cloudfoundry/java-buildpack/blob/master/docs/container-java_main.md, I thought if I add "registration" as an eniviornment variable, the buildpack would supply it to the resulting jar as an argument, so I did set the following enviormment variable:

cf set-env rego-test JBP_CONFIG_JAVA_MAIN: '{arguments: "registration"}'

But it didn't work. It seemed only the microservice-demo-1.1.0.RELEASE.jar is running without the "registration "argument as it prints out usage information in the logs:

2016-06-24T10:10:51.26+1000 [APP/0]      OUT Usage: java -jar ... <server-name> [server-port]
2016-06-24T10:10:51.26+1000 [APP/0]      OUT      where server-name is 'reg', 'registration', 'accounts' or 'web' and server-port > 1024

Attached is the full log and trace from cf restage. logs.txt trace.txt

nebhale commented 8 years ago

I believe that if you run cf env, you'd find out that you've actually set the JBP_CONFIG_JAVA_MAIN: environment variable (note the trailing colon).

A quick testing using a Spring Boot Test Application indicates that argument configuration is working as expected:

$: cf set-env java-main-application JBP_CONFIG_JAVA_MAIN '{arguments: "registration"}'
Setting env variable 'JBP_CONFIG_JAVA_MAIN' to '{arguments: "registration"}' for app java-main-application in [REDACTED] as [REDACTED]...
OK
TIP: Use 'cf restage java-main-application' to ensure your env variable changes take effect
$: cf push
Using manifest file [REDACTED]/java-test-applications/java-main-application/manifest.yml

Using stack cflinuxfs2...
OK
Updating app java-main-application in [REDACTED] as [REDACTED]...
OK

Uploading java-main-application...
Uploading app files from: /var/folders/y_/pn54w0ts14v8c0ybtg2t_qx00000gn/T/unzipped-app366580646
Uploading 554.5K, 88 files
Done uploading               
OK

Starting app java-main-application in [REDACTED] as [REDACTED]...
Creating container
Successfully created container
Downloading app package...
Downloaded app package (20.3M)
Downloading build artifacts cache...
Downloaded build artifacts cache (222.3M)
Staging...
-----> Java Buildpack Version: 7a37ff3 | https://github.com/cloudfoundry/java-buildpack.git#7a37ff3
-----> Downloading Open Jdk JRE 1.8.0_91-unlimited-crypto from https://java-buildpack.cloudfoundry.org/openjdk/trusty/x86_64/openjdk-1.8.0_91-unlimited-crypto.tar.gz (found in cache)
       Expanding Open Jdk JRE to .java-buildpack/open_jdk_jre (1.0s)
-----> Downloading Open JDK Like Memory Calculator 2.0.2_RELEASE from https://java-buildpack.cloudfoundry.org/memory-calculator/trusty/x86_64/memory-calculator-2.0.2_RELEASE.tar.gz (found in cache)
       Memory Settings: -Xms317161K -XX:MetaspaceSize=64M -Xss228K -Xmx317161K -XX:MaxMetaspaceSize=64M
-----> Downloading Postgresql JDBC 9.4.1208 from https://java-buildpack.cloudfoundry.org/postgresql-jdbc/postgresql-jdbc-9.4.1208.jar (found in cache)
-----> Downloading Spring Auto Reconfiguration 1.10.0_RELEASE from https://java-buildpack.cloudfoundry.org/auto-reconfiguration/auto-reconfiguration-1.10.0_RELEASE.jar (found in cache)
Exit status 0
Staging complete
Uploading droplet, build artifacts cache...
Uploading build artifacts cache...
Uploading droplet...
Uploaded build artifacts cache (222.2M)
Uploaded droplet (66.5M)
Uploading complete

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

App started

OK

App java-main-application was started using this command `CALCULATED_MEMORY=$($PWD/.java-buildpack/open_jdk_jre/bin/java-buildpack-memory-calculator-2.0.2_RELEASE -memorySizes=metaspace:64m..,stack:228k.. -memoryWeights=heap:65,metaspace:10,native:15,stack:10 -memoryInitials=heap:100%,metaspace:100% -stackThreads=300 -totMemory=$MEMORY_LIMIT) && JAVA_OPTS="-Djava.io.tmpdir=$TMPDIR -XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk_jre/bin/killjava.sh $CALCULATED_MEMORY -Dspring.main.show_banner=false" && SERVER_PORT=$PORT eval exec $PWD/.java-buildpack/open_jdk_jre/bin/java $JAVA_OPTS -cp $PWD/. org.springframework.boot.loader.JarLauncher registration`

Showing health and status for app java-main-application in [REDACTED] as [REDACTED]...
OK

requested state: started
instances: 1/1
usage: 512M x 1 instances
urls: [REDACTED]
last uploaded: Wed Jul 6 07:21:49 UTC 2016
stack: unknown
buildpack: https://github.com/cloudfoundry/java-buildpack.git

     state     since                    cpu    memory      disk      details
#0   running   2016-07-06 08:22:49 AM   0.0%   0 of 512M   0 of 1G