mvn tomcat7:run

133 views
Skip to first unread message

Ondřej Němeček

unread,
Jun 8, 2015, 6:20:38 PM6/8/15
to acti...@googlegroups.com

Hi to all,

I try to use

mvn tomcat7:run

and it works fine until I use HttpSessionListener in my web.xml.

I implement these SessionCounter

public class SessionCounter implements HttpSessionListener { ... }

and set it in my web.xml:
 
    <listener>
        <listener-class>app.listeners.SessionCounter</listener-class>
    </listener>

It works when running via

mvn jetty:run

but fails  with

mvn tomcat7:run

because Tomcat cannot start:
 
SEVERE: Exception starting filter dispatcher
java.lang.ClassCastException: org.javalite.activeweb.RequestDispatcher cannot be cast to javax.servlet.Filter
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:107)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4775)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5452)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

I quess there is some duplicity in classpath and try change my pom.xml to has javax.servlet-api "provided":

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

But I got

org.javalite.activeweb.CompilationException: src/main/java/app/controllers/ContentController.java:27: error: cannot access HttpSessionListener
        SessionCounter counter = session().get("counter", SessionCounter.class);
                                          ^
  class file for javax.servlet.http.HttpSessionListener not found
1 error

    at org.javalite.activeweb.DynamicClassFactory.getCompiledClass(DynamicClassFactory.java:47)
    at org.javalite.activeweb.DynamicClassFactory.createInstance(DynamicClassFactory.java:23)
    at org.javalite.activeweb.ControllerFactory.createControllerInstance(ControllerFactory.java:27)
    at org.javalite.activeweb.Router.recognize(Router.java:79)

so it looks like there is no javax.servlet duplicity? I stuck in this point.

Important notice: There no problem to run application in normal Tomcat/Jetty deployments.

Any ideas how to solve this? It is not hot problem but is should be nice to be able to run both tomcat and jetty from maven...

Best regards,
Ondrej Nemecek.


Igor Polevoy

unread,
Jun 9, 2015, 2:59:21 PM6/9/15
to acti...@googlegroups.com
Can  you publish your pom? 

Ondřej Němeček

unread,
Jun 10, 2015, 6:45:25 AM6/10/15
to acti...@googlegroups.com

Sure - I attached my pom.xml to this message.

O.
pom.xml

Igor Polevoy

unread,
Jun 10, 2015, 11:54:24 AM6/10/15
to acti...@googlegroups.com
Ondřej, I suggest you remove this from your pom:

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>

Also, move to newer released versions of JavaLite: 

ActiveJDBC: 1.4.10
ActiveWeb: 1.11

tx

Ondřej Němeček

unread,
Jun 10, 2015, 12:57:09 PM6/10/15
to acti...@googlegroups.com

Igor, thanks for reply.

Maybe I missed something, but I cannot compile project without javax.servlet-api dependency in pom.xml because:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project venkovinfo-website: Compilation failure: Compilation failure:
[ERROR] /home/ondrej/Workspacejava/venkovinfo-website/src/main/java/app/listeners/SessionCounter.java:[5,25] error: package javax.servlet.http does not exist
[ERROR] /home/ondrej/Workspacejava/venkovinfo-website/src/main/java/app/listeners/SessionCounter.java:[9,39] error: cannot find symbol
[ERROR] class HttpSessionListener

I also switched to activeweb 1.11 and activejdbc 1.4.10 but got the same result.

See current pom.xml in attachement.

Thanks,
O.
pom.xml

Igor Polevoy

unread,
Jun 10, 2015, 1:01:02 PM6/10/15
to acti...@googlegroups.com
can  you publish SessionCounter source? 

Ondřej Němeček

unread,
Jun 10, 2015, 2:06:29 PM6/10/15
to acti...@googlegroups.com

It is very simple session counter, I took it from stackoverflow :-)

O.
SessionCounter.java

Igor Polevoy

unread,
Jun 10, 2015, 9:03:24 PM6/10/15
to acti...@googlegroups.com
you might have a servlet.jar in tour classpath that is incompatible with servlet 3. 

Please see this: 

Please, ensure that you do not include any servlet jars on your classpath. Look inside the war/WEB-ING/lib and other sensible places, such as Tomcat libs. 
Also, you might want to deploy a really simlple and dumb servlet into your controller and execute this code: 

System.out.println(getClass().getResource("/javax/servlet/Filter.class"));

this will print the URL of the jar file from which the  class file is loaded, so you know where it is coming from. 

tx


On Monday, June 8, 2015 at 5:20:38 PM UTC-5, Ondřej Němeček wrote:
Reply all
Reply to author
Forward
0 new messages