Why build sample petclinic using java 17, but deploy it in azure using java 8?

Charlie Zhang 0 Reputation points
2025-04-27T07:19:39.39+00:00

I download and build the petclinic sample code using java 17, the build is successful and I can run the application on localhost:8080. However, when I follow the step to deploy it to azure cloud service, it requires to use java 8 ( or 1.8) , then I see error. How to fix the issue? can we deploy it using java 17? if so, what is the plug-in id?

This question is related to the following Learning Module

Azure Training
Azure Training
Azure: A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.Training: Instruction to develop new skills.
2,438 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Ruach Nephesh 0 Reputation points
    2025-04-28T01:12:28.4166667+00:00

    Set Azure runtime to Java 17

    Use Maven plugin:

    com.microsoft.azure:azure-webapp-maven-plugin
    

    or

    com.microsoft.azure:azure-spring-apps-maven-plugin
    

    No need to downgrade. Just confirm your pom.xml targets Java 17

    (<maven.compiler.source> and <maven.compiler.target> set to 17).

    1: XML snippet to properly set Java 17 in Maven pom.xml

    Use this inside your <project> block (usually inside <properties>):

    <properties>
        <java.version>17</java.version>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </properties>
    

    This tells Maven to compile your project using Java 17

    Works automatically with standard Azure deployment plugins.


    0 comments No comments

  2. Pradeep M 8,815 Reputation points Microsoft External Staff Moderator
    2025-04-28T04:33:44.35+00:00

    Hi Charlie Zhang

    Thank you for reaching out to Microsoft Q & A forum.  

    Thank you to Ruach Nephesh for providing a good starting point. 

    To clarify: there is no need to downgrade your project to Java 8. You can deploy the Petclinic application using Java 17 by following these steps: 

    Ensure your pom.xml includes the correct Java version settings: 

    <properties>
      <java.version>17</java.version>
      <maven.compiler.source>17</maven.compiler.source>
      <maven.compiler.target>17</maven.compiler.target>
    </properties>
    
    

    In the Azure Maven plugin configuration, update the runtime to use Java 17: 

    <runtime>
      <os>linux</os>
      <javaVersion>Java 17</javaVersion>
    </runtime>
    
    

    It is also recommended to use a newer version of the Azure Maven plugin, such as 2.12.0 or later. 

    The original sample used Java 8 for broader compatibility, but Azure App Service now fully supports Java 17.      

    If you have found the answer provided to be helpful, please click on the "Accept answer/Upvote" button so that it is useful for other members in the Microsoft Q&A community.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.