【发布时间】:2013-03-11 20:11:13
【问题描述】:
我需要从 java/scala 调用一个 clojure 函数,它需要一个向量或一个输入流作为它的第一个参数。
这样做总是会产生以下异常:
执行异常[[UnsupportedOperationException: pdf(clj-pdf.main/-pdf未定义?)]]
我正在使用clj-pdf,需要调用pdf函数
(defn pdf
"usage:
in can be either a vector containing the document or an input stream. If in is an input stream then the forms will be read sequentially from it.
out can be either a string, in which case it's treated as a file name, or an output stream.
NOTE: using the :pages option will cause the complete document to reside in memory as it will need to be post processed."
[in out]
(if (instance? InputStream in)
(stream-doc in out)
(write-doc in out)))
我已经修改了源码,通过
构建了一个jarleiningen uberjar
最后2行可以看到对cjl-pdf的project.clj的修改:
(defproject clj-pdf
"1.0.6"
:description "PDF generation library"
:url "https://github.com/yogthos/clj-pdf"
:license {:name "GNU Lesser General Public License - v 3"
:url "http://www.gnu.org/licenses/lgpl.html"
:distribution :repo
:comments "same as iText and JFreeChart"}
:dependencies [[org.clojure/clojure "1.5.0"]
[jfree/jfreechart "1.0.13"]
[itext-min "0.2"]]
:aot [clj-pdf.main]
:main clj-pdf.main)
在我添加的 main.clj 中:
(ns clj-pdf.main
(:gen-class
;; neither java.io.InputStream nor ArrayList work:
:methods [#^{:static true} [pdf [java.util.ArrayList, java.io.OutputStream] void]])
(:use clj-pdf.core))
(defn -main [& args])
我正在使用我的 scala 代码中的 lib,如下所示:
val output = new ByteArrayOutputStream()
val list = new java.util.ArrayList[String]
list.add( """[:list {:roman true}
[:chunk {:style :bold} "a bold item"] "another item" "yet another item"]
[:phrase "some text"]
[:paragraph "yet more text"]]""")
clj_pdf.main.pdf(list, output)
有没有办法解决这个问题?
【问题讨论】:
-
添加 -pdf 函数没有帮助,仍然抛出相同的 ex。
标签: scala clojure clojure-java-interop