英文:
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 正常配合使用。只需要将其置于列表的首位。
示例:
-
创建一个 apt.yml 文件。
--- packages: - openjdk-11-jdk-headless
-
将其捆绑到您的 JAR 文件中,
jar uf path/to/your/file.jar apt.yml
。它应该被添加到 JAR 文件的根目录中,所以如果您运行jar tf path/to/your/file.jar
命令,您应该只看到apt.yml
,而无需添加任何前缀。 -
更新您的 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
-
然后运行
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:
-
Create an apt.yml.
--- packages: - openjdk-11-jdk-headless
-
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 youjar tf path/to/your/file.jar
you should see justapt.yml
and nothing prefixed to it. -
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
-
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 tojavac
or update the path.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论