Java gurus, I am having trouble calling the metho...
# cfml-general
d
Java gurus, I am having trouble calling the methods of the class from this package: https://repo1.maven.org/maven2/info/picocli/picocli/4.7.6/picocli-4.7.6.jar The programmatic API docs are here: https://picocli.info/picocli-programmatic-api.html and it says I have to use the 3 main model classes CommandSpec, OptionSpec and PositionalParamSpec to define a command. I can load the jar and createObject for CommandLine, but don't know how to call any of its methods, and I don't know how to createObject of CommandSpec. I've tried:
Copy code
commandline = createObject("java", "picocli.CommandLine") // OK
commandspec = createObject("java", "picocli.CommandSpec") // class not found
commandline.CommandSpec() // method not found
I've tried many things and nothing is found. I've have successfully used LaunchDarkly java sdk in cfml. Would really appreciate some help understanding java packages and how they differ when using them programmatically in cfml, and what makes this picocli package differnt than launchdarkly launch darkly source: https://github.com/launchdarkly/java-server-sdk picocli source: https://github.com/remkop/picocli
Just tried another java package called jsoup and its easy to use.
Copy code
jsoup = createObject("java", "org.jsoup.Jsoup")
doc = jsoup.connect("<http://www.nike.com>").get()
writedump(doc.title())
I'm looking at the source code for these 3 packages and their main classes are similar. Picocli is huge compared to the other two, but its very similar. I just can't figure how to use it.
b
I don't really know anything about this library, but there's no
CommandSpec()
method on the
CommandLine
class so I'm not sure why you're trying to call that.
Furthermore, the fqn
picolo.CommandSpec
doesn't exist, so I'm not sure where you got that from either
That class name is
picocli.CommandLine.Model.CommandSpec
The CommandSpec class is enclosed in the Model class which is enclosed in the CommandLIne class
Defo some interesting design .... er ... choices in this Java library
There's 19,000+ lines of code in the main class. Not a very well thought out library IMO, lol
In CF, you need to use a
$
to demarcate inner classes
so you'd get to commandspec as
Copy code
picocli.CommandLine$Model$CommandSpec
d
inner classes with $, right.
b
And then use the static
create()
method to get an instance
d
Awesomeness. It worked
👍 2
b
Can someone present this in a session or maybe a workshop at cfCamp next year please? 😉 "All the ways you never knew to use Java in CF" 🙏
👍🏾 1
👍 2
b
Java interop is always a great topic, though I've found often times the biggest hurdle for CF devs is just understanding how Java works. I knew nothing of Java when I first became a CF dev, and the more I've learned about basic Java stuff, the more it's helped. Just the difference between static and instance data was a huge revelation for me at one point.
👍🏾 1
🙏 1
In addition to the basic CF stuff, BoxLang has really pushed the envelope in terms of java interop, filling in big peices CF was always missing like automatic closure -> lambda bridges, using java methods and functional references, extending Java classes, etc
We have some topics like this submitted to Into The Box already. I plan to be at CFCamp this year, so maybe I can try to submit something along these lines.
🙏 3