Scala REPL无法导入packge [英] Scala REPL unable to import packge

查看:257
本文介绍了Scala REPL无法导入packge的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试导入 com.lambdaworks.crypto.SCryptUtil 来自加密)。我正在从包含com / lambdaworks / crypto的Java目录运行REPL。

I'm trying to import com.lambdaworks.crypto.SCryptUtil (from crypto) in the Scala REPL. I'm running the REPL from the Java directory containing com/lambdaworks/crypto.

REPL找不到 com.lambdaworks.crypto。 SCryptUtil ,但它可以自动完成 com.lambdaworks.crypto 但在此之后找不到任何内容。

The REPL can't find com.lambdaworks.crypto.SCryptUtil, but it can autocomplete up to com.lambdaworks.crypto but can't find anything after that.

当我在项目中包含包后,在IntelliJ IDEA中使用REPL时,我能够找到 SCryptUtil 类。

When I used the REPL in the IntelliJ IDEA after including the package in my project, I was able to find the SCryptUtil class.

我是否遗漏了导入所需的一些类路径参数?

Am I missing some classpath parameters that are required for import?

推荐答案

REPL不会为你编译Java代码 - 它只是自动完成那么远,因为它知道目录结构,但一旦到达加密目录,它将找不到任何类文件。

The REPL won't compile the Java code for you—it's only autocompleting that far because it's aware of the directory structure, but once it gets to the crypto directory it won't find any class files.

通过向上移动目录并打开新的REPL,您可以更加显着地看到这一点 - 您将能够自动完成 import java .com.lambdaworks.crypto ,即使这是obv不是真正的包层次结构。

You can see this more dramatically by moving up a directory and opening a new REPL—you'll be able to autocomplete import java.com.lambdaworks.crypto, even though that's obviously not a real package hierarchy.

在这种情况下,您可以移动到项目根目录,运行 mvn compile 到编译Java代码,然后像这样启动REPL(仍在项目根目录中):

In this case you can move to the project root, run mvn compile to compile the Java code, and then start the REPL like this (still in the project root):

scala -classpath target/classes

现在你可以导入 com.lambdaworks.crypto.SCryptUtil

这只能起作用,因为项目没有任何运行时依赖项,但在其他情况下你可能需要在类路径中添加其他内容,构建一个带有依赖关系的JAR(例如:使用 Maven Assembly插件),或使用 mvn scala:console Maven的目标 Scala插件

This only works because the project doesn't have any runtime dependencies, though—in other cases you may need either to add other things to the classpath, to build a JAR with the dependencies baked in (e.g. with the Maven Assembly plugin), or to use the mvn scala:console goal of the Maven Scala plugin.

这篇关于Scala REPL无法导入packge的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆