But that's another bedtime story altogether. If you do end up wanting nice extras such as TAB-completion or custom key bindings, it has a simple configuration mechanism, and Java API to make the pain of writing custom code as minimal as possible. While the barrier to entry is extremely low, the path to upgrade is but a mild upward slope. JLine truly is a healing salve for your chafing CLI woes. Just like it should have been in the first place. Js: "", line 1: uncaught JavaScript exception: ReferenceError: "prnt" is not defined. In a word: perfect for a beast like java -classpath js.jar:jline.jar jline.ConsoleRunner .shell.Main It can transparently intercept the console input for any java program and seamlessly splice on any and all functionality you'd expect from a hot shell: in-place editing, command history, you name it. What's really cool about JLine is that a program doesn't even need to be written with it. With JLine, building that CLI comes at around 0 cost. It seems that no one in the java world bothers with a decent CLI tragic in my opinion, but probably because it's considered well-understood, non-trivial and therefore tedious. JLine hits a super sweet spot in that it takes somewhere around 0 effort to add loads of standard functionality to your command line interfaces. It's not a problem for me though, thanks to one of my favorite unsung java libraries, JLine. For some reason, the implementors of the Rhino CLI decided to implement their shell with the typical functionality circa 1962. Indeed, what is so wonderful about most modern shells is that the cost for a syntax error is so small. These problems are in particularly nasty contraposition to the technique of exploration via the shell which I advocate because the the cost for failure is so expensive. Js: "", line 29: Compilation produced 2 syntax errors. In this example, we'll implement the interface in java -classpath js.jar .shell.Main You can even extend objects and implement interfaces in javascript! Once again, the command line shows this in action. Not only can you instantiate and use java objects from javascript, but you can also pass in javascript objects as parameters to java methods. ( line 5)Īs you can see, javaString is a reference to an actual object, and has access to all the methods of that class, many of which are not contained in the native javascript String.Įmbedding goes two ways. Js: "", line 5: uncaught JavaScript exception: TypeError: startsWith is not a function. Js> var jsString = new String("Hello World") What exactly is "embedding" an object implemented in Java? If you don't know what this means already, I could try to describe it to you, but why not show it live and in the flesh with the Rhino command line? That's the exploratory technique that I find so java -classpath js.jar .shell.Main Naturally, Spidermonkey is better suited for embedding objects implemented in C, while Rhino excels at embedding objects implemented in Java. They diverge, however, when it comes to embedding objects and functions that are implemented in a language other than javascript. With respect to the javascript runtime itself, these two implementations are almost identical, and so what works in one, will generally work in the other. There are two implementations of the javascript interpreter sponsored by the Mozilla project, Spider Monkey an interpreter implemented in C, and Rhino, an interpreter implemented in Java. I recently described how to use the one of the freely available shells as a great way to explore your javascript runtime.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |