Unable to use Apache Commons CLI Option.builder() in Scala

最后都变了- 提交于 2019-12-23 19:01:04

问题


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()

error: value builder is not a member of object org.apache.commons.cli.Option

I can however see the static fields Option.UNINITIALIZED and Option.UNLIMITED_VALUES

using commons-cli 1.3.1

Scala version: 2.11.8

Spark version: 2.2.0

command to start the shell: spark-shell --jars .m2/repository/commons-cli/commons-cli/1.3.1/commons-cli-1.3.1.jar


回答1:


Let me help you clarify your problem scenario.

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.

This would lead to class collision.

The solution is straightforward, refer the doc, use the compatible constructor method.



来源:https://stackoverflow.com/questions/47319267/unable-to-use-apache-commons-cli-option-builder-in-scala

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!