ClassNotFoundException HikariCP使用Jetty 9的gretty插件

时间:2016-08-25 22:46:01

标签: java gradle jetty hikaricp gretty

我创建了一个Spring演示web application作为概念证明。当我运行类JettyWrapper(嵌入式Jetty)时,它工作正常。但是,当我尝试使用gretty插件运行Jetty 9时,即使在插件类路径中添加了HikariCP,我也得到了ClassNotFoundException的HikariCP。

    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)

如果有人可以提供任何建议和/或指示,将不胜感激。

已编辑 在我解决了这个问题之后,我发现了一个与我another post相关的新问题。在那种情况下,我有一些额外的资源要添加到类路径(configs目录)中,我花了几个小时,直到找到一个没有记录的功能。现在一切正常。

1 个答案:

答案 0 :(得分:2)

如何将库添加到Gretty类路径?

我在gradle.build中用这行做了类似的事情:

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

它运作良好

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

顺便说一句,我也在Gretty推出的网络应用程序中使用HikariCP,但在我的情况下,我以编程方式实例化池,而Hikari库位于webapp类路径中,而不是容器&#39; S