Jetty configuration: problems with MySQL JNDI

喜夏-厌秋 提交于 2020-01-06 20:02:44

问题


The Jetty embedded has a jetty.xml for the configuration. This configuration has a mysql jndi-connection.

When I run jetty with gradle, it throws an exception:

Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
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 com.sahlbach.gradle.plugins.jettyEclipse.JettyEclipseRun.applyJettyXml(JettyEclipseRun.groovy:533)
at com.sahlbach.gradle.plugins.jettyEclipse.JettyEclipseRun.startJetty(JettyEclipseRun.groovy:318)

This is the line of jetty.xml where the exception is thrown:

<New id="relevante" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg></Arg>
    <Arg>jdbc/Relevante</Arg>
    <Arg>
        <New id="relevanteDataSource" class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
           <Set name="url">jdbc:mysql://localhost:3306/xxxx</Set>
           <Set name="user">xxxx</Set>
           <Set name="password">xxxx</Set>
        </New>
     </Arg>
</New>

The MySQL connector is a dependency of gradle and I don't know if I need to place the connector into a local address (in addition to as dependency in gradle).

jettyEclipse {
     additionalRuntimeJars = files( new File("$rootDir/src/main/webapp/WEB-INF/lib/mysql-connector-java-5.0.8-bin.jar") )
     warFile = file("$rootDir/build/libs/relevanteme.war")  
     jettyConfig = file("$rootDir/jetty.xml")
     contextPath = ""
     automaticReload = "true"
     scanIntervalInSeconds = 5
     webDefaultXml = file("$rootDir/webdefault.xml")
}

Thanks!!


回答1:


What's the task to run jetty? Do you know if there is a separate configuration for that and does it extends from compile?




回答2:


The solution's to have two xml files for server configuration. One of these two files will be jetty.xml which will have all the server configuration. The other file will be jetty-env.xml with webApp configuration and connection to the database (this file has to be in webapp/WEB-INF/).

More information in this repository.



来源:https://stackoverflow.com/questions/29652908/jetty-configuration-problems-with-mysql-jndi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!