17

I am working with a Compojure based Clojure web application in IntelliJ using Maven as my dependency manager. It is based on an application I found at this git repository referenced by this example. When I try to run the application using IntelliJ's Tomcat6 configuration, it fails each time citing a Servlet Exception:

javax.servlet.ServletException: Wrapper cannot find servlet class tracker.core or a class it depends on

Additionally looking at the web.xml, IntelliJ does not recognize the servlet class (tracker.core is highlighted).

A little background:

This application was originally was built as a proof of concept for a client and written by my coworker who recently left the company. I personally have no experience with clojure beyond working on this project over the last two days. Using Leiningen ring server, I can successfully get the application to run in jetty. Using leiningen ring uberwar, the resulting war successfully deploys and runs in tomcat.

The original file structure looks like so:

/tracker-webapp  
    /classes
    /lib
    /resources
    /src
        /tracker
            /core.clj (and other *.clj files)
    /test
    project.clj

The new mavenized file structure now mirrors the example in the previously mentioned git repo:

/tracker-webapp
    /src
        /main
            /clojure
                /tracker
                    /core.clj (and other *.clj files)
            /webapp
                /WEB-INF
                    /web.xml
    /pom.xml

My web.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>

  <display-name>Simple Clojure WebApp</display-name>
  <servlet>
    <servlet-name>myservlet</servlet-name>
    <servlet-class>tracker.core</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>myservlet</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>

</web-app>

Other Resources

I was going to post the other resources that I've looked at in this section but since I'm a Stack Overflow Newb I only get two links :/

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
MplsAmigo
  • 985
  • 6
  • 21
  • Other Resources I've looked at: - http://stackoverflow.com/questions/5354038/clojure-compojure-maven-application-doesnt-work-in-tomcat - http://assenkolov.blogspot.com/2011/11/sample-clojurecompojure-web-application.html - http://alexott.net/en/clojure/ClojureMaven.html - http://stuartsierra.com/2009/09/03/mavens-not-so-bad – MplsAmigo Feb 03 '12 at 15:58
  • I think I know what's going on, I'm going to take a closer look at home. I'm pretty sure it has to do with Clojure's gen-class functionality, but need to poke around a bit to get you a solution. – deterb Feb 07 '12 at 21:58
  • Did you find out the root cause of the problem? – Rob Kielty May 17 '12 at 07:42
  • How do you build the warfile (the one that gives the error)? A project.clj might help if you're using Leiningen. – Rasputnik Mar 04 '13 at 22:36
  • 1
    Did you check that the class tracker.core is actually generated? it sounds like a problem with the genclass declaration (:gen-class :extends javax.servlet.http.HttpServlet) – Denis Fuenzalida Mar 16 '13 at 21:36
  • It has been many years now since this question. Unfortunately I am working in different technologies and no longer have the ability to speak to answers that may or may not work. I never did find a solution to the problem, however @ordnungswidrig's answer sounds promising. – MplsAmigo Apr 20 '15 at 19:43

1 Answers1

1

You need to compile your clojure namespace tracker.core ahead-of-time (AOT). I'm not sure how this is done with the maven plugin but it gives you the right direction.

Make sure that you have a gen-class declaration in your namespace:

(ns tracker.core
  ;; ...
  (:gen-class :extends javax.servlet.http.HttpServlet))

Check that Intellij/Maven actually produce the file tracker/core.class in the target directory.

ordnungswidrig
  • 3,140
  • 1
  • 18
  • 29