无法在Scala中使用Apache Commons CLI Option.builder() [英] Unable to use Apache Commons CLI Option.builder() in Scala
问题描述
在Spark Shell或应用程序中(用Scala/maven构建编写),我无法使用Apache Commons CLI包中的静态生成器方法.我已经确认我将jar包含在类路径中,并且可以访问Option
类以及包中的其他类(如Options
,DefaultParser
等).为什么不能在斯卡拉(Scala)?
In a spark shell or application (written in Scala/maven build), I am unable to use the static builder method from the Apache Commons CLI package. I have confirmed that I am including the jar in the class path and have access to the Option
class along with other classes in the package like Options
, DefaultParser
, etc. Why can I not use this public static method in Scala?
import org.apache.commons.cli.Option
val opt = Option.builder("foo").build()
错误:值生成器不是对象org.apache.commons.cli.Option的成员
error: value builder is not a member of object org.apache.commons.cli.Option
但是我可以看到静态字段Option.UNINITIALIZED
和Option.UNLIMITED_VALUES
I can however see the static fields Option.UNINITIALIZED
and Option.UNLIMITED_VALUES
火花版本: 2.2.0
命令启动外壳程序: spark-shell --jars .m2/repository/commons-cli/commons-cli/1.3.1/commons-cli-1.3.1.jar
推荐答案
让我帮助您弄清问题所在.
Let me help you clarify your problem scenario.
您可以打开您的 .idea文件夹,发现它已经具有一些内部jar依赖项,并且存在commons_cli列表,但 1.2版本.
You can open your .idea folder, find that it have some internal jar dependencies already, and of the list commons_cli exists, but 1.2 version.
这会导致类冲突.
解决方案很简单,请参考 doc ,使用兼容的构造方法.
The solution is straightforward, refer the doc, use the compatible constructor method.
这篇关于无法在Scala中使用Apache Commons CLI Option.builder()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!