Blog Post

Apps on Azure Blog
3 MIN READ

Getting Started with Java WebJobs on Azure App Service

denverbrittain's avatar
Mar 26, 2025

Learn to deploy and run scheduled WebJobs using Java on Azure App Service.

Getting Started with Linux WebJobs on App Service - Java

 

WebJobs Intro

WebJobs is a feature of Azure App Service that enables you to run a program or script in the same instance as a web app. All app service plans support WebJobs. There's no extra cost to use WebJobs. This sample uses a Triggered (scheduled) WebJob to output the system time once every 15 minutes.

Create Web App

Before creating our WebJobs, we need to create an App Service webapp. If you already have an App Service Web App, skip to the next step Otherwise, in the portal, select App Services > Create > Web App. After following the create instructions and selecting one of the Java runtime stacks, create your App Service Web App. The stack must be Java, since we plan on writing our WebJob using Java and a bash startup script.

Next, we’ll add a basic WebJob to our app.

Create WebJob

Before we do anything else, let’s write our WebJob. This will execute every time our WebJob is triggered. WebJobs on App Service can be run on a Triggered (Scheduled) basis or Continuously. This example uses a Triggered WebJob.

For this example, we’ll need to compress two files into a zip archive that we’ll upload to our App Service Web App. We’ll need a startup script and an executable jar.

The full code for this sample is available at: https://github.com/Azure-Samples/App-Service-Java-WebJobs-QuickStart

Digging into the code, our Java project located at project/src/main/java/webjob/HelloWorld.java is relatively simple. It just outputs a message & the current time to the console.

import java.time.LocalDateTime;
public class HelloWorld {
  public static void main(String[] args) {
    System.out.println("------------------------------------------------------------");
    System.out.println("Hello World from WebJob: " + LocalDateTime.now());
    System.out.println("------------------------------------------------------------");
  }
}

The run.sh script located at the root of our git repo, just runs a jar with the name that we’ve set in our maven configuration. This script will run when our WebJob is triggered, and it is the job of this script to kick off our Java executable (jar).

java -jar webjob-artifact-1.0.0.jar

Now we need to compile our Java project to produce the executable jar. There are multiple ways to do this, but for this example, we’ll use Maven. Run the following commands from the project/ directory:

mvn install
mvn package

After successfully building our app with mvn package, our jar file will be located at project/target/webjob-artifact-1.0.0.jar.

Now we have everything we need to assemble our zip file. Again, there are multiple ways to do this, but for this demo we’ll use the zip CLI utility to create our zip file called webjob.zip. First move your jar file to the root of the git repo with project/target/webjob-artifact-1.0.0.jar. Then run the zip command to package our application as a zip file.

zip webjob.zip run.sh webjob-artifact-1.0.0.jar

Now it’s time to create our WebJob and upload our zip file.

Create WebJob in Portal

Start by entering your Web App overview page. Then, under Settings select WebJobs. Here we can create and manage our App Service WebJobs for this Web App. Click Add to create a new WebJob.

 

 

 

Now we can name our WebJob, upload our zip from the previous step, and choose our execution type. Under Type, select Triggered. Under CRON Expression, enter the following to trigger our WebJob once every 15 minutes.

 

0 */15 * * * *

 

Note: These are NCRONTAB expressions, not standard Linux CRONTAB expressions. An important distinction.

Now click Create WebJob to finish making our new WebJob. Let’s test it out now.

 

Run Manually or Scheduled

To manually test our WebJob, we can click the play button under Run. A status of Completed means that WebJob is finished.

Confirm Results in Logs

We can check the logs to confirm that the console print statements from our Java file were output to the console.

 

 

While this is a basic example, WebJobs are a powerful and easy to use feature that have incredible utility for running scheduled (or continuous) actions in conjunction with your App Service Web Apps at no additional cost.

Learn more about WebJobs on App Service

 

 

Published Mar 26, 2025
Version 1.0
No CommentsBe the first to comment