java.lang.ClassNotFoundException:javax.servlet.http.HttpSessionIdListener

时间:2016-03-24 08:42:17

标签: java maven classnotfoundexception

我有两个项目可以自己正确运行但是当我在TradingFramework中包含MailSender时,我得到了这个NoClassDefFoundError:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/servlet/http/HttpSessionIdListener
    at org.eclipse.jetty.server.session.SessionHandler.<clinit>(SessionHandler.java:54)
    at org.eclipse.jetty.servlet.ServletContextHandler.newSessionHandler(ServletContextHandler.java:298)
    at org.eclipse.jetty.servlet.ServletContextHandler.getSessionHandler(ServletContextHandler.java:393)
    at org.eclipse.jetty.servlet.ServletContextHandler.relinkHandlers(ServletContextHandler.java:181)
    at org.eclipse.jetty.servlet.ServletContextHandler.<init>(ServletContextHandler.java:168)
    at org.eclipse.jetty.servlet.ServletContextHandler.<init>(ServletContextHandler.java:124)
    at org.eclipse.jetty.servlet.ServletContextHandler.<init>(ServletContextHandler.java:112)
    at com.destek.utils.websocket.WebSocketServer.createWebSocketHandler(WebSocketServer.java:102)
    at com.destek.utils.websocket.WebSocketServer.createContextHandler(WebSocketServer.java:82)
    at com.destek.utils.websocket.WebSocketServer.start(WebSocketServer.java:51)
    at com.destek.onlinetradingfwk.service.websocket.WebSocketServerMain.runServer(WebSocketServerMain.java:25)
    at client.TradeGateway.main(TradeGateway.java:174)
Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpSessionIdListener
    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)
    ... 12 more

我排除了冲突的罐子,但它仍然是相同的。以下是pom.xml文件:

交易框架:

<dependency>
  <groupId>com.destek</groupId>
  <artifactId>metaman-java-wrapper</artifactId>
  <version>2.4</version>
</dependency>
<dependency>
  <groupId>com.destek</groupId>
  <artifactId>json-over-fix-adapter</artifactId>
  <version>0.1</version>
</dependency>
<dependency>
  <groupId>com.destek.tools</groupId>
  <artifactId>web-socket-server</artifactId>
  <version>1.0</version>
</dependency>
<dependency>
  <groupId>org.apache.commons</groupId>
  <artifactId>commons-lang3</artifactId>
  <version>3.4</version>
</dependency>
<dependency>
  <groupId>commons-beanutils</groupId>
  <artifactId>commons-beanutils</artifactId>
  <version>1.9.2</version>
</dependency>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.12</version>
</dependency>
<dependency>
  <groupId>org.mockito</groupId>
  <artifactId>mockito-core</artifactId>
  <version>2.0.31-beta</version>
</dependency>
<dependency>
  <groupId>com.destek</groupId>
  <artifactId>quickfixj-all</artifactId>
  <version>1.4.1</version>
</dependency>
<dependency>
  <groupId>org.apache.mina</groupId>
  <artifactId>mina-core</artifactId>
  <version>1.1.7</version>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.7.7</version>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>1.7.7</version>
</dependency>
<dependency>
  <groupId>log4j</groupId>
  <artifactId>log4j</artifactId>
  <version>1.2.17</version>
  <scope>runtime</scope>
</dependency>

<dependency>
  <groupId>log4j</groupId>
  <artifactId>apache-log4j-extras</artifactId>
  <version>1.2.17</version>
</dependency>

<dependency>
  <groupId>javax.websocket</groupId>
  <artifactId>javax.websocket-api</artifactId>
  <version>1.1</version>
</dependency>

<dependency>
  <groupId>com.nimbusds</groupId>
  <artifactId>nimbus-jose-jwt</artifactId>
  <version>4.4</version>
</dependency>

<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>5.1.6</version>
</dependency>

<dependency>
  <groupId>com.zaxxer</groupId>
  <artifactId>HikariCP</artifactId>
  <version>2.4.3</version>
</dependency>
<dependency> 
    <groupId>com</groupId> 
    <artifactId>MailSender</artifactId> 
    <version>1.0</version> 
    <exclusions>
        <exclusion>
            <groupId>org.ow2.asm</groupId>
            <artifactId>asm-debug-all</artifactId>
        </exclusion>
        <exclusion>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
    </exclusion>
    <exclusion>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
    </exclusion>
    <exclusion>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
    </exclusion>
    </exclusions>
</dependency>

MailSender:

    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet</artifactId>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.test-framework.providers</groupId>
        <artifactId>jersey-test-framework-provider-grizzly2</artifactId>
    </dependency>

    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-multipart</artifactId>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-json-jackson</artifactId>
        <version>2.17</version>
    </dependency>
    <dependency>
        <groupId>org.bouncycastle</groupId>
        <artifactId>bcprov-jdk16</artifactId>
        <version>1.46</version>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.7</version>
    </dependency>
    <!-- slf4j log -->
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.7.12</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.12</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.6</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.7.1</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>7.0</version>
        <type>jar</type>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20140107</version>
    </dependency>
    <dependency>
        <groupId>net.lingala.zip4j</groupId>
        <artifactId>zip4j</artifactId>
        <version>1.2.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.3.2</version>
    </dependency>

2 个答案:

答案 0 :(得分:15)

<!-- http://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
</dependency>

注意

  

的javax.servlet-API

而不是

  

servlet的API

答案 1 :(得分:0)

包括javax.servlet api的maven依赖,类似这样的

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0</version>
<scope>provided</scope>

请参阅this了解更多