REPL中使用自定义Java类

REPL中使用自定义Java类

本文介绍了在Clojure REPL中使用自定义Java类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Eclipse中,使用CCW插件,我想将clojure文件加载到REPL中。问题是,我有一个import语句为我自己的java类,但显然不是在我的类路径。

In Eclipse, using the CCW plug-in, I want to load a clojure file into a REPL. The problem is that I have an import statement for one of my own java classes, but apparently it is not in my classpath.

(ns my-clj-ns
  (:import [alg.gen Enumerator]))

我必须在Clojure REPL中使用/测试每个类吗?

Do I have to make jars out of every class that I want use/test in a Clojure REPL?

目前,尝试将我的clj加载到REPL中会导致错误:
在Clojure REPL中加载文件未正常完成。有关详细信息,请参阅日志。
java.lang.NullPointerException

Currently, trying to load my clj into a REPL results in an error:"Load file in Clojure REPL" did not complete normally. Please see the log for more information.java.lang.NullPointerException

任何帮助将非常感激。

推荐答案

您的代码对我来说很好。

Your code looks fine to me.

我怀疑问题是您的Eclipse Java Build Path Eclipse包含在您的应用程序的类路径中。

I suspect the issue is with your Eclipse Java Build Path, which determines what Eclipse includes in the classpath for your application.

特别是,如果您的Java类位于单独的项目中,您需要将该项目添加到构建路径右键单击项目/ Properties / Java Build Path / Projects)或将其打包为jar。

In particular, if your Java class is in a separate project, you will need to either add that project to the build path (right click on project / Properties / Java Build Path / Projects) or package it as a jar.

当你开始有更复杂的构建需求时,开始查看来为您处理这类事情。 Maven是一个痛苦学习/设置在第一,但它支付的长期。

When you start to have more sophisticated build requirements, you may also want to start looking at Maven to handle this kind of thing for you. Maven is a pain to learn / set up in the first place but it pays of in the long run.

也是一个很好的工具但我个人不使用它的原因如下:

Leiningen is also a great tool to use but I personally don't use it for the following reasons:


  1. 它在命令行上很好,但是没有集成这么好使用Eclipse工作流程

  2. Maven在Java世界中使用更广泛,并得到更好的支持

这篇关于在Clojure REPL中使用自定义Java类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 06:49