简体   繁体   中英

ClassNotFoundException HikariCP with gretty plugin using Jetty 9

I created a Spring demo web application as a proof of concept. It works fine when I run the class JettyWrapper (embedded Jetty). However when I'm trying to run run Jetty 9 using the gretty plugin I'm getting a ClassNotFoundException of HikariCP even adding the HikariCP in the plugin classpath.

    jetty.xml config file

    ...
    <New class="com.zaxxer.hikari.HikariDataSource">
        <Arg>
            <New id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
                <Set name="poolName"><SystemProperty name="hikaricp.poolName" default="HikariCP"/></Set>
                <Set name="driverClassName"><SystemProperty name="hikaricp.driverClassName" default="org.hsqldb.jdbc.JDBCDriver"/></Set>
                <Set name="idleTimeout"><SystemProperty name="hikaricp.idleTimeout" default="10000"/></Set>
                <Set name="maximumPoolSize"><SystemProperty name="hikaricp.maximumPoolSize" default="5"/></Set>
                <Set name="username"><SystemProperty name="hikaricp.username" default="SA"/></Set>
                <Set name="password"><SystemProperty name="hikaricp.password" default=""/></Set>
                <Set name="jdbcUrl"><SystemProperty name="hikaricp.jdbcUrl" default="jdbc:hsqldb:hsql://localhost/demodb"/></Set>
                <Set name="connectionTestQuery"><SystemProperty name="hikaricp.connectionTestQuery" default="SET DATABASE SQL SYNTAX MYS TRUE"/></Set>
                <Set name="connectionInitSql"><SystemProperty name="hikaricp.connectionInitSql" default="SET DATABASE SQL SYNTAX MYS TRUE"/>
                </Set>
            </New>
        </Arg>
    </New>
    ...


Exception in thread "main" java.lang.ClassNotFoundException: com.zaxxer.hikari.HikariDataSource
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.eclipse.jetty.util.Loader.loadClass(Loader.java:86)
    at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.nodeClass(XmlConfiguration.java:364)
    at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:754)
    at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.itemValue(XmlConfiguration.java:1125)
    at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.value(XmlConfiguration.java:1030)
    at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:775)
    at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:423)
    at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:298)
    at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:248)
    at org.eclipse.jetty.xml.XmlConfiguration$configure.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    at org.akhikhl.gretty.JettyConfigurerImpl.applyJettyXml(JettyConfigurerImpl.groovy:64)
    at org.akhikhl.gretty.JettyConfigurer$applyJettyXml$0.call(Unknown Source)

If anyone can help with any tips and/or directions will be greatly appreciated.

EDITED: After I got this problem solved, I found a new problem related what made me another post . In that case I had some extra resources to be added in the classpath (configs dir) and I spent a couple hours until I found a non documented feature. Now everything is working fine.

How are you adding the library to Gretty classpath?

I've done something similar with this line in my gradle.build:

dependencies { ///... gretty 'my:library:version' }

And it worked great

http://akhikhl.github.io/gretty-doc/Servlet-container-classpath.html

By the way, I'm also using HikariCP in a web app launched by Gretty, but in my case I'm instantiating the pool programatically, and the Hikari library is in the webapp classpath, not in the container's.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM