0

Suppose when I make a java spring boot application, it needs jars .

But when I deploy my app to cloud foundry will all the jars get build with my app and then go to cloud foundry or cloud foundry provides the jars dependency by seeing pom etc. I have seen build folder but the jars are not there so how does it work. I am new to cloud foundry so if someone can clear my doubt.

pradeep
  • 31
  • 7

2 Answers2

2

For most application types and build packs, when you push an application to Cloud Foundry you are pushing source code, and, if necessary, that source codes gets compiled during the staging process by the build pack. For example, with the Golang build pack you push your Go source code and it's compiled in staging and then run.

The two exceptions to this rule are the Java build pack and the binary build pack. These two build packs assume that you are pushing compiled bits and do not compile anything for you.

In the case of Java, this means that you're going to run Maven, Gradle or some other build system locally or on your CI system to produce a deployable artifact. This could be a WAR file or a JAR file, or a few other things (see "Standard Containers" on the Java build pack docs for other supported formats). Regardless of the format, it needs to be a complete and deployable unit, so it will need to include all dependent libraries.

As a side note, the cf cli has a nice feature that helps to speed up the cf push process and save bandwidth. It matches any files being uploaded and over 65k in size (default, operators can change this) to files cached on the Cloud Controller. If a local file already exists in the cache, it is not uploaded again. This works great for dependent JAR files which don't often change between pushes.

Daniel Mikusa
  • 13,716
  • 1
  • 22
  • 28
1

Spring Boot apps are typically packaged as "fat jars" using the Spring Boot maven or gradle plugin. The application code and all dependent jars are packaged into a single jar file.

Cloud Foundry will not download dependent jars when a Java application is deployed. It is the app's responsibility to bring all dependencies with it.

Scott Frederick
  • 4,184
  • 19
  • 22
  • So how do I go about 'bringing all dependencies with it'? If I do internalize all dependencies into a fat jar, one of my dependencies requires an external configuration file. Can I push the config file up with my spring boot jar? My experience so far says that the java buildpack no longer detects the spring boot app if I push a directory instead of a single file. – Pickles May 07 '18 at 06:45
  • If you pass a directory to `cf push -p`, the CLI will upload all files in the directory. If you pass an archive (.jar, .war, .zip) to `cf push -p`, the CLI will unpack locally and upload the contained files. Buildpacks always see a list of files, and Java buildpack expects to see a set of .class files. If cf CLI sends a directory containing one .jar file and one configuration file, JBP won't detect a Java application. – Scott Frederick May 07 '18 at 17:56
  • Does the external config file contain Spring Boot properties, or is it a config file for some library that expects to be able to read from the file system? A few suggestions for external config are discussed here: https://stackoverflow.com/questions/43506324/spring-boot-app-on-cloud-with-external-properties-file. – Scott Frederick May 07 '18 at 17:57
  • @ScottFrederick It's a custom configuration/license file for a specific library, which doesn't have the ability to read from an external location. The path to the config file can be set via an environment variable. I have been able to work around it by simply unzipping the spring boot jar in the same folder as the manifest, and including the configuration file in that folder. In that case, everything is uploaded together. I guess that's the expected way to do it without bundling the config file into the jar. – Pickles May 08 '18 at 08:59
  • If the config file can't be bundled into the jar at build time (e.g. as a post-processing step after the Boot build plugin has built the fat jar), then I can't think of anything better than your current solution. – Scott Frederick May 08 '18 at 16:47