How can I add "javax.mail.jar", "mysql-connector-j-9.0.0.jar" and the context.xml to an Azure App Service with Java 11 and Tomcat 9?

Sven Auer 20 Reputation points
2024-08-26T18:41:27.5133333+00:00

How can I add "javax.mail.jar", "mysql-connector-j-9.0.0.jar" and the context.xml to an Azure App Service with Java 11 and Tomcat 9?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,931 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sina Salam 22,031 Reputation points Volunteer Moderator
    2024-08-26T22:29:28.55+00:00

    Hello Sven Auer,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that you would like to deploy Java app to Azure App Service and you want to know how you can add "javax.mail.jar", "mysql-connector-j-9.0.0.jar" and the context.xml to an Azure App Service with Java 11 and Tomcat 9.

    It starts with your code plartform:

        <dependency>
             <groupId>com.mysql</groupId>
             <artifactId>mysql-connector-j</artifactId>
             <version>9.0.0</version>
    
    

    https://www.digitalocean.com/community/tutorials/javamail-example-send-mail-in-java-smtp

         <dependency>
             <groupId>javax.mail</groupId>
             <artifactId>javax.mail</artifactId>
             <version>x.y.z</version>
         </dependency>
    

    Then, create a context.xml file for your web application (usually located in the META-INF directory). In this file you will define your database connection settings, such as the data source, username, password, and other relevant properties. For a sample it looks like:

         <Context>
             <Resource name="jdbc/MyDB" auth="Container"
                       type="javax.sql.DataSource"
                       driverClassName="com.mysql.cj.jdbc.Driver"
                       url="jdbc:mysql://your-mysql-server:3306/your-database"
                       username="your-username"
                       password="your-password"
                       maxTotal="20"
                       maxIdle="10"
                       maxWaitMillis="-1"/>
         </Context>
    

    Finally, deploy your Java application (WAR file) to your Azure App Service and make sure the context.xml file is included in your deployment package. After this, ensure you configure the Azure App Service to use Java 11 and Tomcat 9.

    https://learn.microsoft.com/en-us/azure/app-service/configure-language-java-deploy-run?source=recommendations

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.

    ** Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful ** so that others in the community facing similar issues can easily find the solution.

    Best Regards,

    Sina Salam

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.