云计算基金会和JDK

huangapple go评论80阅读模式
英文:

CloudFoundry and JDK

问题

我在部署一个需要在运行时编译Java代码的Spring应用时遇到了问题。我的应用在用户提交问题的解决方案时调用javac命令,以便稍后可以运行java <javac生成的文件>。

我正在部署到Cloud Foundry并使用Java Buildpack,但不幸的是,它不带有JDK,只提供JRE,而该环境中没有javac或java命令。

你们是否知道如何在Cloud Foundry上添加JDK,而无需编写自定义的构建包?

谢谢

英文:

I'm struggling with the deployment of a spring app that needs to compile java code during runtime. My app calls the javac command when a user submits a solution to a problem, so it can later run java <the file that javac has generated>

I'm deploying to cloud foundry and using the java-buildpack, but unfortunately, it doesn't come with JDK, only JRE is available and that thing has no javac or java commands available.

Do you guys know a way on how to add JDK to cloud foundry, without having to write my own custom buildpack.

Thanks

答案1

得分: 1

我建议您使用多个构建包支持,并使用 apt-buildpack 安装 JDK。它应该可以与 JBP 正常配合使用。只需要将其置于列表的首位。

示例:

  1. 创建一个 apt.yml 文件。

     ---
     packages:
     - openjdk-11-jdk-headless
    
  2. 将其捆绑到您的 JAR 文件中,jar uf path/to/your/file.jar apt.yml。它应该被添加到 JAR 文件的根目录中,所以如果您运行 jar tf path/to/your/file.jar 命令,您应该只看到 apt.yml,而无需添加任何前缀。

  3. 更新您的 manifest.yml 文件。将 apt-buildpack 添加到列表的首位。

     ---
     applications:
     - name: spring-music
       memory: 1G
       path: build/libs/spring-music-1.0.jar
       buildpacks:
       - https://github.com/cloudfoundry/apt-buildpack#v0.2.2
       - java_buildpack
    
  4. 然后运行 cf push 命令。您应该会看到 apt-buildpack 开始运行并安装 JDK。然后,它将安装在 ~/deps/0/lib/jvm/java-11-openjdk-amd64 目录下。它似乎也没有出现在 PATH 中,因此请使用完整路径来调用 javac,或者更新路径设置。

英文:

I would suggest you use multi-buildpack support and use the apt-buildpack to install a JDK. It should work fine alongside the JBP. It just needs to be first in the list.

https://github.com/cloudfoundry/apt-buildpack

Example:

  1. Create an apt.yml.

     ---
     packages:
     - openjdk-11-jdk-headless
    
  2. Bundle that into your JAR, jar uf path/to/your/file.jar apt.yml. It should be added to the root of the JAR, so if you jar tf path/to/your/file.jar you should see just apt.yml and nothing prefixed to it.

  3. Update your manifest.yml. Add the apt-buildpack first in the list.

     ---
     applications:
     - name: spring-music
       memory: 1G
       path: build/libs/spring-music-1.0.jar
       buildpacks:
       - https://github.com/cloudfoundry/apt-buildpack#v0.2.2
       - java_buildpack
    
  4. Then cf push. You should see the apt-buildpack run and install the JDK. It'll then be installed under ~/deps/0/lib/jvm/java-11-openjdk-amd64. It does not appear to end up on the PATH either, so use a full path to javac or update the path.

huangapple
  • 本文由 发表于 2020年9月17日 04:20:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/63927417.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定