Jetty会话聚类ClassNotFoundException

时间:2016-03-24 03:44:49

标签: java mysql jdbc jetty

我正在使用http://www.eclipse.org/jetty/documentation/current/session-clustering-jdbc.html

实现jetty会话群集

我的jetty-jdbc-sessions.xml文件看起来像

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">

<Configure id="Server" class="org.eclipse.jetty.server.Server">


  <!-- ===================================================================== -->
  <!-- Configure a SessionIdManager                                          -->
  <!-- ===================================================================== -->
  <Set name="sessionIdManager">
    <New id="idMgr" class="org.eclipse.jetty.server.session.JDBCSessionIdManager">
      <Arg>
        <Ref refid="Server"/>
      </Arg>
      <Set name="workerName"><Property name="jetty.jdbcSession.workerName" default="node1"/></Set>
      <Set name="scavengeInterval"><Property name="jetty.jdbcSession.scavenge" default="1800"/></Set>

      <!-- ===================================================================== -->
      <!-- Uncomment either the datasource or driver setup and configure         -->
      <!-- ===================================================================== -->

      <!--
          <Set name="DatasourceName"><Property name="jetty.jdbcSession.datasource" default="javax.sql.DataSource/default"/></Set>
      -->

        <Call name="setDriverInfo">
          <Arg><Property name="jetty.jdbcSession.driverClass"/></Arg>
          <Arg><Property name="jetty.jdbcSession.connectionURL"/></Arg>
        </Call>

    </New>
  </Set>

</Configure>

Start.ini

# --------------------------------------- 
# Module: jdbc-sessions
--module=jdbc-sessions
## JDBC Session config

## Unique identifier for this node in the cluster
  jetty.jdbcSession.workerName=node1

## The interval in seconds between sweeps of the scavenger
# jetty.jdbcSession.scavenge=600

## Uncomment either the datasource name or driverClass and connectionURL
# jetty.jdbcSession.datasource=sessions
 jetty.jdbcSession.driverClass=com.mysql.jdbc.Driver
 jetty.jdbcSession.connectionURL=jdbc:mysql://127.0.0.1:3306/sessions;create=true

当我用java -jar start.jar启动jetty时,我得到了异常

2016-03-23 22:36:49.124:WARN:oejuc.AbstractLifeCycle:main: FAILED org.eclipse.jetty.server.session.JDBCSessionIdManager
7591a3ed: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at org.eclipse.jetty.server.session.JDBCSessionIdManager.initializeDatabase(JDBCSessionIdManager.java:1496)
        at org.eclipse.jetty.server.session.JDBCSessionIdManager.doStart(JDBCSessionIdManager.java:985)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
        at org.eclipse.jetty.server.Server.start(Server.java:387)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
        at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
        at org.eclipse.jetty.server.Server.doStart(Server.java:354)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
        at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1255)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1174)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.jetty.start.Main.invokeMain(Main.java:321)
        at org.eclipse.jetty.start.Main.start(Main.java:817)

我在$ JETTY_HOME / lib目录和$ JAVA_HOME / lib目录中都有我的mysql jdbc驱动程序jar文件,所以我不确定为什么我仍然会收到错误

2 个答案:

答案 0 :(得分:3)

将MySQL JDBC Driver jar放在$JETTY_HOME/lib/ext目录中。

答案 1 :(得分:1)

我必须在start.init中为jetty添加--module = ext来处理来自lib / ext目录的jar。