Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to use Apache Commons CLI Option.builder() in 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()

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

like image 437
Chadderall Avatar asked Oct 24 '25 08:10

Chadderall


1 Answers

Problem Source

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.

like image 193
ashburshui Avatar answered Oct 27 '25 01:10

ashburshui