user193116
user193116

Reputation: 3568

How to merge several Clojure Web (Compojure) applications into one?

I had decomposed a business solution into multiple smaller web applications and created those small web applications using Lein Compjure plugin.( This enabled for faster development ). I am now trying to merge these web applications into one web application ,lets call it unifiedapp ,by creating a new lein compojure project and adding the smaller web applications as dependencies. I will create the approprite app routes in the unifiedapp such that the correct handler from the smaller web apps will be invoked.

The problem I am facing is that the lein does not take war files as dependency and when I try to create a simple jar file for a lein compojure project( small web app, it fails.

Edit: project.clj ( this is generated by lein new compojure hello-world)

(defproject hello-world "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :min-lein-version "2.0.0"
  :dependencies [[org.clojure/clojure "1.8.0"]
                 [compojure "1.5.1"]
                 [ring/ring-defaults "0.2.1"]]
  :plugins [[lein-ring "0.9.7"]]
  :ring {:handler hello-world.handler/app}
  :profiles
  {:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
                        [ring/ring-mock "0.3.0"]]}})

When I run lein jar install , I get the following message:

Warning: The Main-Class specified does not exist within the jar. It may not be executable as expected. A gen-class directive may be missing in the namespace which contains the main method, or the namespace has not been AOT-compiled.

I do see a jar file in the target folder but for some reason, it does not copy over the jar file to .m2\repository . Therefore the parent web application that is trying to include this jar (routes of this web application) cannot see it.

Upvotes: 1

Views: 118

Answers (1)

user193116
user193116

Reputation: 3568

Thanks to Alan's response, I changed my approach. I did not merge the source by I modified the main web application's project.cj file to include source and resources used the the child/sub-applications

(defproject mainwebapp "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :min-lein-version "2.0.0"
  :dependencies [[org.clojure/clojure "1.8.0"]
                 [compojure "1.5.1"]
                 [ring/ring-defaults "0.2.1"]]

  :source-paths ["../app1/src" "../app2/src" "../app3/src"  "src"]    
 :resource-paths ["../app1/resources" "../app2/resources" "../app3/resources" ] 

  :plugins [[lein-ring "0.9.7"]]
  :ring {:handler mainwebapp.handler/app}
  :profiles
  {:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
                        [ring/ring-mock "0.3.0"]]}})

Upvotes: 0

Related Questions