How to use context.xml in embbed tomcat with gradle please?

445 Views Asked by At

My environment:

Gradle 4.8

openjdk version "1.8.0_181"

My dirs like :

/src/main/webapp/META-INF/context.xml

And in context.xml, I put a db resource:

<Resource
    name="jdbc/my_db"
    type="javax.sql.DataSource"
    driverClassName="com.mysql.jdbc.Driver"
    url="jdbc:mysql://localhost:3306/my_db"
/>

in my build.gradle, I use :

apply plugin: 'java'
apply plugin: 'war' 
apply plugin: 'com.bmuschko.tomcat'
/*... some dependencies ... */
tomcat {
    httpPort = 8080
    httpsPort = 8443
    enableSSL = false
    contextPath = '/'
}

In a jsp, I write

<sql:setDataSource dataSource="jdbc/my_db" />

to use it.

Last I use gradle tomcatRun, and I can access some jsps. but can not find db. error is:

Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for jdbc/my_db"

What is my wrong please? And how to fix it please?

BTW: I see the build/libs/gradle.war file, and context.xml in it.

0

There are 0 best solutions below