4 ms·
when i want to play with java stuff interactively i just actually open it up in clojure repl
by beanjuiceII 3y ago
when i want to play with java stuff interactively i just actually open it up in clojure repl
- artpar 3y agoI have actually never used clojure repl, I'll check it out. How does it work with application code ? Or is it for Java SDK ? I encourage you to give this a try, surely this should be less context switching if you are using intellij as your ide.
- preordained 3y agoYou can open a Clojure REPL in IntelliJ. But, you need nrepl running in your server/running Clojure
- jiehong 3y agoA jshell session can also work for that, but IntelliJ doesn’t add all your classes to the module path so jshell doesn’t usually know about them, which is a big oversight IMO.
- artpar 3y agoYou can provide the classpath to the jshell (usually jshell -c target/classes) and with that jshell can locate your compiled classes. But you will have to create the instances of your target class object (plus all of its dependencies) which is going to be really cumbersome. Consider a Spring service class which uses another redis service and a database service and you want to call a method on this service. So now you have to create the redis service first (copy/paste their config values etc), then the database service and then the actual spring service you want to test. Once you have created the service, now you need to create the parameter values required by your target method, which you would either create using a new Xyz(), variable.setX, setY and so on, or alternatively now try to import a JSON mapper (ok so now we need to add the classpath to the dependencies as well), and then reconstruct the parameter with objectMapper.readValueAsString("{json here}", Xyz.class); You can see how this gets unnecessarily complicated depending on the project you are working with. So with direct invoke you have all the class instances ready in the correct state and you can just call a function. The service classes are being setup by your start up procedure anyways. And for the parameters we are currently using the objectMapper approach so its all setup and ready to use.