《Living Clojure》cheshire-cat项目运行lein ring server遇编译异常求解决
解决
lein ring server启动编译异常的方案 问题根源
你使用的是2014年的旧版依赖与插件,这类版本针对Java 8设计,和现代Java环境(Java 9+)存在兼容性冲突,同时依赖间版本不匹配也会触发编译错误。
具体修改方案
以下是调整后的project.clj配置,可解决版本兼容与环境适配问题:
(defproject cheshire-cat "0.1.0-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :min-lein-version "2.9.0" ;; 更新最低Leiningen版本要求 :dependencies [[org.clojure/clojure "1.10.3"] ;; 升级到稳定兼容版 [compojure "1.6.2"] [ring/ring-defaults "0.3.2"] [ring/ring-json "0.5.1"] [org.clojure/clojurescript "1.10.879"] ;; 升级ClojureScript [cljs-http "0.1.60"] [org.clojure/core.async "1.5.648"] [enfocus "2.1.1"]] :plugins [[lein-ring "0.12.6"] ;; 升级插件版本 [lein-cljsbuild "1.1.8"]] :ring {:handler cheshire-cat.core.handler/app} :jvm-opts ["--add-modules" "java.xml.bind"] ;; 适配Java 9+的JAXB模块缺失问题 :profiles {:dev {:dependencies [[javax.servlet/servlet-api "2.5"] [ring-mock "0.1.5"]]}} :cljsbuild { :builds [{ :source-paths ["src-cljs"] :compiler { :output-to "resources/public/main.js" :optimizations :whitespace :pretty-print true :source-map true}}]}) ;; 添加源码映射方便调试
修改说明
- 升级核心依赖:将Clojure、Compojure、Ring系列依赖更新到兼容现代Java环境的稳定版本,解决旧版本API缺失或冲突问题。
- 更新ClojureScript生态依赖:新版ClojureScript修复了大量旧版编译bug,同时兼容新版core.async与cljs-http。
- 升级Leiningen插件:新版lein-ring和lein-cljsbuild支持新版依赖,避免插件与依赖的版本不匹配错误。
- Java 9+适配:添加
:jvm-opts配置,手动引入Java 9+中移除的JAXB模块,解决类找不到的异常。
修改完成后,先执行lein clean清理旧编译文件,再运行lein ring server即可正常启动服务。
内容的提问来源于stack exchange,提问作者taydilemle
相关产品推荐
相关产品推荐

