Skip to content

Commit 4ca872e

Browse files
committed
java updates
1 parent e19d626 commit 4ca872e

File tree

1 file changed

+56
-43
lines changed

1 file changed

+56
-43
lines changed

articles/app-service/quickstart-webjobs.md

Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -238,67 +238,80 @@ WebJobs is a feature of Azure App Service that enables you to run a program
238238

239239
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio).
240240
- An existing App Service [Java app](quickstart-java.md).
241+
- [Maven Plugin for Azure App Service Web Apps](https://github.com/microsoft/azure-maven-plugins/blob/develop/azure-webapp-maven-plugin/README.md).
241242
- **[Always on](configure-common.md?tabs=portal#configure-general-settings)** must be enabled on your app.
242243
- Ensure the App setting `WEBSITE_SKIP_RUNNING_KUDUAGENT` is set to `false`.
243244

244245
## Create your sample WebJob
245246

246-
1. In this step, you create a basic .NET WebJob project and navigate to the project root.
247+
[A sample Java WebJob](https://github.com/Azure-Samples/App-Service-Java-WebJobs-QuickStart) has been created for you. In this section, you review the sample and then build a `.JAR` file using Maven in the Cloud Shell.
247248

248-
```bash
249-
dotnet new console -n webjob –framework net9.0
250-
251-
cd webjob
252-
```
249+
### Review the sample
253250

254-
1. Next, replace `Program.cs` to the following code that writes the current time to the console:
251+
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.
255252

256-
```dotnet
257-
using System;
258-
259-
class Program
260-
{
261-
static void Main()
262-
{
263-
DateTimeOffset now = DateTimeOffset.Now;
264-
Console.WriteLine("Current time with is: " + now.ToString("hh:mm:ss tt zzz"));
265-
}
266-
}
267-
```
253+
```Java
254+
import java.time.LocalDateTime;
268255

269-
1. From the *webjob* directory, run the webjob to confirm the current time is output to the console:
256+
public class HelloWorld {
270257

271-
```bash
272-
dotnet run
273-
```
258+
public static void main(String[] args) {
274259

275-
You should see output similar to the following:
260+
System.out.println("------------------------------------------------------------");
261+
System.out.println("Hello World from WebJob: " + LocalDateTime.now());
262+
System.out.println("------------------------------------------------------------");
263+
}
264+
}
265+
```
276266

277-
```bash
278-
Current time with is: 07:53:07 PM -05:00
279-
```
267+
### Build the Java WebJob
280268

281-
1. Once you've confirmed the app works, build it and navigate to the parent directory:
269+
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).
282270

283-
```bash
284-
dotnet build --self-contained
285-
286-
cd ..
287-
```
271+
```bash
272+
java -jar webjob-artifact-1.0.0.jar
273+
```
288274

289-
1. Next we to create `run.sh` with the following code:
275+
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:
290276

291-
```text
292-
#!/bin/bash
293-
294-
dotnet webjob/bin/Debug/net9.0/webjob.dll
295-
```
277+
```bash
278+
mvn install
279+
mvn package
280+
```
281+
After successfully building our app with `mvn package`, our jar file will be located at `project/target/webjob-artifact-1.0.0.jar`.
296282

297-
1. Now package all the files into a .zip as shown below:
283+
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.
284+
285+
```bash
286+
287+
zip webjob.zip run.sh webjob-artifact-1.0.0.jar
288+
289+
```
290+
## Create a scheduled WebJob on Azure
291+
292+
1. In the [Azure portal](https://portal.azure.com), go to the **App Service** page of your App Service app.
293+
294+
1. From the left pane, select **WebJobs**, then select **Add**.
298295

299-
```bash
300-
zip webjob.zip run.sh webjob/bin/Debug/net9.0/*
301-
```
296+
:::image type="content" source="media/webjobs-create/add-webjob.png" alt-text="Screenshot that shows how to add a WebJob in an App Service app in the portal (scheduled WebJob).":::
297+
298+
1. Fill in the **Add WebJob** settings as specified in the table, then select **Create Webjob**. For **File Upload**, be sure to select the .zip file you downloaded earlier in the [Download the sample WebJob](#download-the-sample-webjob) section.
299+
300+
:::image type="content" source="media/webjobs-create/configure-new-scheduled-webjob.png" alt-text="Screenshot that shows how to configure a scheduled WebJob in an App Service app.":::
301+
302+
| Setting | value | Description  |
303+
| ------------ | ----------------- | ------------ |
304+
| **Name** | webjob | The WebJob name. Must start with a letter or a number and must not contain special characters other than "-" and "_". |
305+
| **File Upload** | App-Service-PHP-WebJobs-Quickstart-Main.zip | The *.zip* file that contains your executable or script file. The supported file types are listed in the [supported file types](webjobs-create.md?tabs=windowscode#acceptablefiles) section. |
306+
| **Type** | Triggered | Specifies when the WebJob runs: Continuous or Triggered. |
307+
| **Triggers** | Scheduled | Scheduled or Manual. Ensure [Always on](configure-common.md?tabs=portal#configure-general-settings) is enabled for the schedule to work reliably.|
308+
| **CRON Expression** | 0 0/1 * * * * | For this quickstart, we use a schedule that runs every minute. See [CRON expressions](webjobs-create.md?tabs=windowscode#ncrontab-expressions) to learn more about the syntax. |
309+
310+
1. The new WebJob appears on the **WebJobs** page. If you see a message that says the WebJob was added, but you don't see it, select **Refresh**.
311+
312+
1. The scheduled WebJob is run at the schedule defined by the CRON expression.
313+
314+
:::image type="content" source="media/webjobs-create/scheduled-webjob-run.png" alt-text="Screenshot that shows how to run a manually scheduled WebJob in the Azure portal.":::
302315

303316
:::zone-end
304317

0 commit comments

Comments
 (0)