Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure Webapp in IntelliJ + Maven + Tomcat

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 :/

like image 507
MplsAmigo Avatar asked Feb 03 '12 15:02

MplsAmigo


1 Answers

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.

like image 136
ordnungswidrig Avatar answered Nov 02 '22 23:11

ordnungswidrig