akhikhl / gretty

Advanced gradle plugin for running web-apps on jetty and tomcat.
MIT License
654 stars 174 forks source link

How to add JDBC jar files to Tomcat bootstrap classpath ? #427

Closed samba4vineti closed 6 years ago

samba4vineti commented 6 years ago

I am trying to run Tomcat within my Eclipse environment and connect to my PostgreSQL DB. I keep running into java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory

Based on comments on this (https://github.com/akhikhl/gretty/issues/98) thread, I configured my gradle to include gretty at multiple levels, with no success. Below are 2 ways I configured the dependencies. Config 1 : which throws the same error as above dependencies { def tomcatVersion = '8.5.24'

gretty 'org.apache.tomcat:tomcat-jdbc:8.5.24'
gretty 'org.apache.commons:commons-dbcp2:2.1.1'
gretty 'org.postgresql:postgresql:42.2.1'

compile 'commons-dbcp:commons-dbcp:1.4',
        'org.postgresql:postgresql:42.2.1', ......

Config 2 : which also fails with above error gretty { contextPath = 'app' contextConfigFile = file('context.xml'); enableNaming = true scanInterval= 2 scanDependencies = true

dependencies {
    gretty 'org.apache.tomcat:tomcat-jdbc:8.5.24'
    gretty 'org.apache.commons:commons-dbcp2:2.1.1'
    gretty 'org.postgresql:postgresql:42.2.1'
}

}

Would appreciate any help on this front. Been breaking my head on this for some time now. :-(

javabrett commented 6 years ago

Try adding compile group: 'org.apache.tomcat', name: 'tomcat-dbcp', version: '8.5.24'. It contains the class you are missing.

samba4vineti commented 6 years ago

Thanks for the quick response. I did try adding it to the compile list of dependencies, as below, and still get the error. :-( compile 'commons-dbcp:commons-dbcp:1.4', 'org.postgresql:postgresql:42.2.1', 'org.apache.tomcat:tomcat-jdbc:8.5.24' Presume this should be added to the top level "dependencies" function and not within the "gretty" function. BTW, I tried both the options. :-(

javabrett commented 6 years ago

Where did you add tomcat-dbcp? I still don't see it. Perhaps past some files as gists.

samba4vineti commented 6 years ago

Oh my !!! Thanks a lot. I was confused between the different but very similarly named jars. Below is what I ended up with and it works perfectly now. Thanks so much !!

gretty { contextPath = 'cape' contextConfigFile = file('context.xml'); enableNaming = true scanInterval= 2 scanDependencies = true // ... many more properties

dependencies {
    gretty 'org.apache.tomcat:tomcat-jdbc:8.5.24'
    //gretty 'org.apache.commons:commons-dbcp2:2.1.1'
    gretty 'org.postgresql:postgresql:42.2.1'
    gretty 'org.apache.tomcat:tomcat-dbcp:8.5.24'
}   

} BTW, I didn't need to add these JAR files to the top level dependencies{} function. Thanks much once again !!

javabrett commented 6 years ago

Sure, please close the issue. And if/when you next need to upgrade, a few of us have started a fork for v2.1.0+ over at https://github.com/gretty-gradle-plugin/gretty .

samba4vineti commented 6 years ago

Thanks. Will check out the fork.