简体   繁体   English

如何使用Clojure的Apache Commons Codec库?

[英]How do I use the Apache Commons Codec library from Clojure?

I'm trying to use the Base 64 functions present in the Apache Commons Codec package. 我正在尝试使用Apache Commons Codec包中的Base 64函数 I'm using Leiningen, and have this in my project.clj : 我正在使用Leiningen,并在我的project.clj有这个:

:dependencies [[org.clojure/clojure "1.2.0"]
               [commons-codec/commons-codec "1.4"]]

Leiningen successfully finds the appropriate .jar. 莱宁根成功找到合适的.jar。 I can't for the life of me figure out which class I actually need to import, though. 我不能为我的生活弄清楚我实际上需要导入哪个类。 I have tried all variations of 我尝试了所有的变化

(ns my-project.core
  (:import (org.apache.commons.codec.binary Base64)))

but nothing seems to work. 但似乎没什么用。 What class name should I be using for this? 我应该使用什么类名?

I would recommend cutting to the chase and checking where the rubber hits the road. 我建议切入追逐并检查橡胶撞到路面的位置。 Make sure Leiningen did in fact place the correct jar in the lib directory of your project. 确保Leiningen确实将正确的jar放在项目的lib目录中。 Open the jar and look inside and see of the class you are looking for is there. 打开罐子,看看里面,看看你正在寻找的课程。 If the path to that class in the jar should match the path of your import statement. 如果jar中该类的路径应与import语句的路径匹配。

Whoops. 哎呦。 It looks like I was just calling the class itself incorrectly. 看起来我只是错误地调用了类本身。 The following worked fine after the :import line above: (.decode (Base64.) s) . 以下内容之后工作正常:import上面的:import行:( (.decode (Base64.) s) Thanks for the responses, everyone. 感谢大家的回复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM