user2228156
user2228156

Reputation: 37

JDK availability in Cloud Foundry

I am trying to call javac from within a Cloud Foundry Java app to compile a java file during runtime of the app. I have a question about which JDK is being used.

To test this, in my app, I instantiated a JavaCompiler using statement ToolProvider.getSystemJavaCompiler() and print out the compiler instance. The app was deployed on CF and printed out: com.sun.tools.javac.api.JavacTool@2e68d3ad

The following came from the log.

-----> Java Buildpack Version: v3.13 | https://github.com/cloudfoundry/java-buildpack.git#03b493f 2017-04-24T13:23:21.38-0700 [STG/0] OUT -----> Downloading Open Jdk JRE 1.8.0_121 from https://java-buildpack.cloudfoundry.org/openjdk/trusty/x86_64/openjdk-1.8.0_121.tar.gz (0.5s) 2017-04-24T13:23:22.48-0700 [STG/0] OUT Expanding Open Jdk JRE to .java-buildpack/open_jdk_jre (1.0s)

Two questions:

  1. Is it safe to assume a JDK is always available on Cloud Foundry, so I can use javac.
  2. Why the compiler instantiated in my code refers to Sun's javac? I was expecting OpenJDK JDK( even though the log said only the JRE is downloaded ).

Any insight will be appreciated. Thanks. -Michelle

Upvotes: 1

Views: 2361

Answers (1)

Daniel Mikusa
Daniel Mikusa

Reputation: 15051

Is it safe to assume a JDK is always available on Cloud Foundry, so I can use javac.

The javac utility is not installed by the build pack. If you look closely at what it is installing, you'll see that it's installing a JRE and not a JDK. The JRE is just the runtime and does not contain javac.

2017-04-24T13:23:21.38-0700 [STG/0] OUT -----> Downloading Open Jdk JRE 1.8.0_121 from https://java-buildpack.cloudfoundry.org/openjdk/trusty/x86_64/openjdk-1.8.0_121.tar.gz (0.5s)

Note how it says "Open JDK JRE". "Open JDK" is the name of the Java implementation and "JRE" is the type.

You can confirm by running cf ssh into an app deployed with the Java build pack. If you look at /home/vcap/app/.java-buildpack/, you can see what all is installed.

This is all that I see under the bin directory.

~/app/.java-buildpack/open_jdk_jre$ ls bin/
java                                            jcmd  jmap    keytool      orbd     policytool  rmiregistry  tnameserv
java-buildpack-memory-calculator-2.0.2_RELEASE  jjs   jstack  killjava.sh  pack200  rmid        servertool   unpack200

Why the compiler instantiated in my code refers to Sun's javac? I was expecting OpenJDK JDK( even though the log said only the JRE is downloaded ).

I suspect that it's because OpenJDK came out of Sun, so there is still some shared heritage.

https://en.wikipedia.org/wiki/OpenJDK#History

Upvotes: 2

Related Questions