Build and Deploy your Java app to an Azure web app

Last Update: 4/11/2017

Team Services | TFS 2017 | TFS 2015 | Previous versions: XAML Build, Release

In just a few steps you can build and deploy your Java app to Azure. This works from both the Visual Studio Team Services service and your on-premises Team Foundation Server.

Upload your code

Upload your code to Visual Studio Team Services or your on-premises Team Foundation Server. Either push your code to Git or check in your code to TFVC.

If you don't have any code, you can download our Hello world Java web app.

What code is in the sample app?

Enable Java, Apache Tomcat, and FTP for your Azure web app

  1. Sign in to the Azure portal.

  2. Edit or create a Java web app and enable Apache Tomcat.

  3. Click the deployment credentials part (outlined in red below). Create a user name and password. Click Save. If you previously enabled publishing for a web app, you don't need to do this step.

    Create FTP deployment credentials

Create the definition

  1. Open your team project in your web browser ▼

    Browse to team project

    (If you don't see your team project listed on the home page, select Browse.)

    • On-premises TFS: http://{your_server}:8080/tfs/DefaultCollection/{your_team_project}
    • Visual Studio Team Services: https://{your_account}.visualstudio.com/DefaultCollection/{your_team_project}

    The TFS URL doesn't work for me. How can I get the correct URL?

  2. Create a build definition (Build & Release tab > Builds) ▼

    Build tab

  3. Click Empty to start with an empty definition.

Define variables to store Azure FTP authentication data

On the Variables tab, store the data needed to copy files to Azure via FTP. Copy this data from the Azure portal. There is nothing special about the variable names we suggest below, so you can make them whatever you prefer.

Name Notes
azure.ftp.userName Take this value from your Azure web app essentials. For example if the name of your Azure web app is FabrikamJava, then the value would be : FabrikamJava\YourUserName
azure.ftp.password Take this value from your Azure subscription deployment settings. In your build definition variables, make sure to click secret to avoid exposing this password value. I don't want to use my Azure subscription FTP credentials. Can I use credentials scoped to my Azure web app?

Java deployment build variables

Add build steps

On the Build tab, add these steps:

Build: Maven Build: Maven

Build the app.

  • Maven POM file: Browse and select your pom.xml file. For example, helloworld/pom.xml.
Utility: cURL Upload Files Utility: cURL Upload Files

Copy the .war file to Azure.

  • Files: helloworld/target/hello.war
  • Username: $(azure.ftp.userName)
  • Password: $(azure.ftp.password)
  • URL: Take this value from your Azure web app essentials page on the Azure portal. For example, ftp://waws-prod-sn1-011.ftp.azurewebsites.windows.net
  • Optional Arguments: -Q "+CWD site/wwwroot/webapps"
Utility: Copy and Publish Build Artifacts Build: Publish Build Artifacts

(Optional) Drop some of the build outputs, such as the .war file as we do in the example below.

  • Copy Root: helloworld/target
  • Contents: hello.war
  • Artifact name: drop
  • Artifact Type: Server

Finish and test the definition

  1. On the Repository tab:

    • Git: Make sure the repository and branch containing your application are selected. (By default the repository with the same name as the team project is selected.)

    • TFVC: Make sure the folder that contains your app is mapped.

  2. On the Triggers tab select continuous integration (CI). If your code is in Git, specify the branches you want to build.

  3. Save your definition and queue the build.

After a successful build, check your site: http://{web_app_name}.azurewebsites.net/{war_file_name}

Q&A

What code is in the sample app?

We used Eclipse to create our Hello World Java sample web app. We adapted a project created from the maven webapp archetype.

|-- .gitignore
`-- helloworld
    |-- .classpath
    |-- .project
    |-- pom.xml
    `-- src
        `-- main
            `-- webapp
                |-- WEB-INF
                |   `-- web.xml
                `-- index.jsp

The pom.xml file enables you to build with Maven. The .gitignore file keeps build artifacts on your dev machine from getting into your Git repo.

I don't want to use my Azure subscription FTP credentials. Can I use credentials scoped to my Azure web app?

A: Yes.

  1. Sign in to the Azure portal.

  2. Open your web app and download the publish profile.

  3. Open your .PublishSettings file and copy some of the data from the publishMethod="FTP" section into your build variables.

Name Value from .PublishSettings file attribute Notes
azure.ftp.userName userName For example, YourAppName\$YourAppName
azure.ftp.password userPWD In your build definition variables, make sure to click secret to avoid exposing this password value.

How do I continually deliver my app and manage my releases?

Learn about Release Management

What other kinds of apps can I build?

Build your app

What other kinds of build steps are available?

Specify your build steps

How do we protect our codebase from build breaks?

How do I modify other parts of my build definition?

I selected parallel multi-configuration, but only one build is running at a time.

If you're using Team Services, you might need more concurrent pipelines. See Concurrent build and release pipelines in Visual Studio Team Services.

How do I see what has changed in my build definition?

View the change history of your build definition

Do I need an agent?

You need at least one agent to run your build or release. Get an agent.

I can't select a default agent queue and I can't queue my build or release. How do I fix this?

See queues.

I use Team Foundation Server on-premises and I don't see some of these features. Why not?

Some of these features are available only on Visual Studio Team Services and not yet available on-premises. Some features are available on-premises if you have upgraded to the latest version of TFS.