如何确定需要从 java 库导入哪个命名空间?
我正在编写一些 clojure 代码,并且依靠 Joda time 进行时间处理。问题是我不知道要导入什么,并且文档对此也不是很清楚。现在我知道这里有人可能可以在不到 5 秒的时间内给我正确的答案,但我宁愿知道如何自己解决这个问题(除了翻阅文档直到找到正确答案之外)。
如果我在 Python 中执行此操作,我将导入顶级包并使用 dir
和 help
的组合来找出我需要导入的内容。在 Clojure 中有什么方法可以做到这一点吗?或者还有其他类型的java工具可以解决这个问题吗?我更喜欢面向命令行的东西。
I'm writing some clojure code, and I'm relying on Joda time for time handling. The problem is that I don't know what to import and the documentation isn't terribly clear about it. Now I know that somebody here can probably give me the correct answer in less than 5 seconds, but I'd rather know how to figure this one out on my own (aside from pouring through the docs until I find the correct answer).
If I were doing this in Python, I'd import the top-level package and use a combination of dir
and help
to figure out what I need to import. Is there any way to do this in clojure? Or are there any other kinds of java tools to figure this out? I'd prefer something that's command-line oriented.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
通常我会选择 David Grant 的答案,但如果您找不到任何 JavaDoc (!),但您有一个 jar 文件,则可以使用 jar 实用程序列出 jar 中的文件。
类文件所在的目录直接映射到其包名称。例如,jar -tf joda-time-1.6.jar | more 将 DateTime.class 列为 org/joda/time/DateTime.class; DateTime 位于 org.joda.time 包中。
Normally I'd go with David Grant's answer, but if you can't find any JavaDoc (!), but you have a jar file, you can use the jar utility to list the files in the jar.
The directory the class files are in map directly to its package name. For example,
jar -tf joda-time-1.6.jar | more
lists DateTime.class asorg/joda/time/DateTime.class
; DateTime is in theorg.joda.time
package.就像
dir
和help
将检查 Python 中的包的文档一样,Java 中的有用信息可以通过阅读特定 API 的 Javadoc 来收集。对于 Joda Time,该网站有一个指向生成文档的直接链接,此处:http://joda-time.sourceforge.net/api-release/index.html (参见左下框)
我想不出任何可以直接与您所要求的内容相比较的东西,因为除非您向类加载器询问特定的类,否则类加载器不会加载它,并且您将无法找到它。
In the same way that
dir
andhelp
will examine the documentation of packages in Python, useful information in Java can be gleaned from reading the Javadocs for a particular API. In the case of Joda Time, the web site has a direct link to the generated documentation, here:http://joda-time.sourceforge.net/api-release/index.html (see the bottom left frame)
I can't think of anything off hand that is directly comparable to what you ask, since unless you ask the classloader for a particular class, the classloader won't load it, and you won't be able to find it.
Bill Clementson 编写了一小段代码,可帮助您从重复。
Bill Clementson has written a small piece of code that helps you view the javadoc documentation from the REPL.
http://dishevelled.net/Generate-Clojure-import-lines-使用-SLIME.html
使查找进口变得非常容易。就我个人而言,我只是使用 REPL 中定义的 clojure 函数 find-classes。
http://dishevelled.net/Generating-Clojure-import-lines-using-SLIME.html
Makes it really easy to look up imports. Personally I just use the clojure function find-classes defined there from the REPL.