简体   繁体   中英

Cloud Foundry, run-task, simple HelloWorld.java

i just want to have a simple Application like Hello World run as a Task on CloudFoundry.

So i want to cf run-task myapp firstArgument secondArgument

Is it possible to deploy an app on Cloud Foundry and start this jar like on a linux Console.

java -jar simpleApp.jar firstargument seconArgument 

Yes, that is 100% possible.

  1. Build your application & compile it.
  2. Package it into a JAR file that can be executed. Test & confirm locally by running java -jar your-app.jar .
  3. Now cf push -p path/to/youar-app.jar your application. The Java buildpack should detect the app & install the software required to run the app.
  4. The Java buildpack & CloudFoundry in general expect the app that you push to start & run forever. If your application does not, if it's meant to start and only run for a finite period of time, the app is going to fail to start but that's OK. You can ignore that. After it fails, run cf stop .
  5. If you have a task that runs for a finite period of time, you need one additional step. Run cf run-task <your-app> <arg1> <arg2> ... . The trick is that Java will not be on the $PATH so you need to use the full path to the Java executable, which is .java-buildpack/open_jdk_jre/bin/java . For example, if you wanted to print the Java version, cf run-task your-cool-app ".java-buildpack/open_jdk_jre/bin/java -version" (make sure you have the command quoted, escape quotes within the command accordingly).

See this SO post for more background on running tasks: https://stackoverflow.com/a/67872218/1585136

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM