I am thinking about writing a Java application where the user can write some modules in Java and add them to a library in this application. The modules will be some calculations that use data from the main app. Maybe a bit like VBA in Office.
I would appreciate if someone would give me some hints where to start as I couldn't find something useful on the net.
Thanks in advance!
You can try to develop a module framework from scratch, if you wish.
However, if you are developing anything serious you should consider using OSGi.
Theoretically it is possible. You can allow user to write java classes, then you can compile the class using java compiler, generate .class files. you can load them using your custom class loader (probably URLClassLoader or its subclass, etc.
BUT
It is very serious application. Actually it is a kind of IDE. So, of you really want this check out a possibility to create Eclipse based application, i.e. implement several eclipse plugins.
Other approach may be to allow user wring code in one of popular scripting languages. For example groovy that has java-like syntax but can be run without compilation and does not require creating classes etc. Javascript is an option too. Javascript interpreter is a part of JDK, so you even do not need external dependencies.
you might be better off incorporating some form of jvm scripting language. Something like groovy, jruby or jython. Those don't need actual compilation and can be stored in your system as source. Plus they can be quite nice to write code in too. Groovy has the advantage of being a superset of java. (For the most part) you could just degrade to java code, and run it in the groovy interpreter.
Related
I'm looking to get started with javafx and fxml, without downloading netbeans (as the official docs suggests: https://docs.oracle.com/javafx/2/get_started/fxml_tutorial.htm), eclipse or scenebuilder. I'm looking to use a simple text editor and terminal, similar to the way someone might create an html,css and javascript project. Is this possible, or is the only way to use fxml and javafx through netbeans or some other similar tool?
Technically speaking, in any programming language, IDE is always optional.
You can write all your source codes (.java, .css, .fxml) files using any text editor that you like (like Notepad++), then go to a command-line interface (i.e. terminal, command prompt etc) and compile them, pretty much like how you would compile a Swing application.
The advantages of doing so? Pretty much simply because you can do this without any unnecessary downloads.
The disadvantages? You have to be VERY VERY clear on every single details about Java and JavaFX.
You need to be extremely familiar with building and compiling Java applications manually. You need to do your own build path in order to compile right.
There is nothing there that will instantly tell you that you have made a mistake (be it minor or major, or even a typo). You will only see where went wrong after you re-compile via command-line.
You have to do your imports manually (in both java and fxml). This means that you would have to know the exact package names and class names.
Most of the time, you would have to imagine how your application would look like visually. The only time if you know you designed right is when you re-compile and run it via command-line.
HTML, CSS, Javascript are considered scripting language. This means that these codes do not require code compilation, and that there is a base application/process that is running in the background to interpret what you wrote in English terms (or at least it is very close to English).
Languages like Java are true programming language, they require you to compile them, and running them will most likely create a new process on the OS.
So the conclusion is, it is definitely possible to do so, but you would probably end up using 10x (if not 100x) more time doing the same thing. IDE is there to help you do some of the tedious things. If you really want to do it using the traditional command-line method, ask a new question on that.
As I've recently started using JRuby, more specifically building Java applications using Ruby code, I've started using Java Libraries such as LWJGL and Slick.
I know JRuby changes Java method names to a more ruby-esque structure, my question is, is there any current way to generate Ruby documentation, either from source or by conversion of current documentation or even based on what JRuby exposes the methods themselves as?
At some point when JRuby 1.6.7 is out I plan on cleaning this really rough project for just such a thing:
https://github.com/enebo/noridoc
The intention is it will weave both Java and Ruby syntax together and give reasonable documentation for a Rubyist wanting to know all Ruby methods. In it's current form you should be able to generate a reasonable set of HTML docs of Java code showing you all ruby aliased methods. You will need to screw around with the javadoc comment.
Oh and we plan on making this tool available out of the box in JRuby once it is good enough to merge.
I have many questions about scala. I have done a bit of reading and googling and SO'ing and not found any solid answers readily available. I'm not at the experimentation/prototyping stage yet, so I thought I might as well just ask my questions and get some expert knowledge for everyone to share. Thanks in advance!
What is scala.exe really for? Can someone give a rundown about what scala.exe does differently than java.exe? Is there runtime black magic in scala.exe other than providing for an interpreter shell?
(UPDATE: There is no such thing as a scala.exe. Scala ships with a simple batch script launcher, scala.bat (or scala on *nix). The Scala runtime is java.exe with Scala's standard library jars in the CLASSPATH.)
Can I link in scala code to an existing java program if I launched the process with java.exe? If so, does my CLASSPATH need to change to link in the scala standard library jars? Also if I am launching with java.exe, are any new -javaagent parameters required to link in scala code? Is there a way to include scala code in jars in my existing web application .war file (or in WEB-INF/classes) and have it run?
Conversely, if scala.exe is required in my Java EE app server launcher to execute scala+java code, can scala.exe take all my esoteric -XX:InsertYourCrazySunPerfSwitchHere JVM command line parameters?
Finally, is incorporating new Scala code into an existing Spring Framework + JSF2 web application like trying to fit a round peg into a square hole? I see long lists of web frameworks designed for Scala that are available, but I wondered how smooth or how awkward Scala would be playing with commodity tools like JSF2. Are these Scala-based web frameworks the byproduct of non-Java developers migrating to the Scala community and wanting to recreate their framework du jour in the Scala language? Or, is there something intrinsic about the way JSF2 is designed such that, once I became an expert at Scala, I would see it's a sloppy mess trying to mix the two and I had wasted my time?
You have asked many questions. I will try to address them all, one at a time.
Question:
What is scala.exe really for? Can someone give a rundown about what
scala.exe does differently than java.exe? Is there runtime black magic
in scala.exe other than providing for an interpreter shell?
scala.bat can do several things depending on the arguments:
it can launch an interpreter shell
it can execute a Scala script file
it can execute a compiled Scala binary from a classpath
it can execute a jar file
When launching binaries, scala.bat will simply call java.exe with scala-library.jar added to the classpath. There is no magic of any kind.
Question:
Can I link in scala code to an existing java program if I launched the
process with java.exe? If so, does my CLASSPATH need to change to link
in the scala standard library jars? Also if I am launching with
java.exe, are any new -javaagent parameters required to link in scala
code?
All the Scala binaries are simple jars. The only difference is that they require the scala runtime library (scala-library.jar). So when launching with java.exe you simply follow the steps you would when launching a jar with dependencies. Again, there is no magic and no extra switches.
Question:
Is there a way to include scala code in jars in my existing web
application .war file (or in WEB-INF/classes) and have it run?
Scala jars are just like java jars, so you can treat them as such.
Question:
Finally, is incorporating new Scala code into an existing Spring
Framework + JSF2 web application like trying to fit a round peg into a
square hole? I see long lists of web frameworks designed for Scala
that are available, but I wondered how smooth or how awkward Scala
would be playing with commodity tools like JSF2. Are these Scala-based
web frameworks the byproduct of non-Java developers migrating to the
Scala community and wanting to recreate their framework du jour in the
Scala language? Or, is there something intrinsic about the way JSF2 is
designed such that, once I became an expert at Scala, I would see it's
a sloppy mess trying to mix the two and I had wasted my time?
Using Java libraries from Scala is at least as easy as using them from Java and often much smoother. On the other hand Scala is much richer that Java. So you will feel that Java libraries are lacking as soon as you start getting used to Scala.
I have a project which will need to have some Java layer. I am wondering it if is reasonable to try to avoid using jRuby by having the Ruby code call some URL that would invoke a Java controller, which, I guess, would return some JSON.
Is that a reasonable approach? Or does it have inherent problems when in comes to architecture and would be a pain in the long run?
Also, if it is just Ruby, can it still be hosted on Tomcat and be part of my .war file? And What is that rails part that I will seem to be missing?
You could do it either way. For me it would be easier not to involve Java in the mix, and keep Ruby talking to JRuby. Also, I'm not sure if you know this or not, but JRuby is also available as a self contained interpreter. Look for the complete jar in the download page.
Also, if Java is a must, you could call the Ruby code from Java, via the scripting engines, as presented here
I'd rather not "reinvent the wheel" and I've found a Ruby project that provides functionality I need in my Java app (there is no preexisting Java project that does what I need - trust me, I've looked). So, best case scenario, I am able to run the Ruby code from my Java code (ala JSR223).
However, this Ruby project depends on having several gems installed. I'm not at all interested in converting the entire Java app into a JRuby app, but I'd like to be able to leverage this project. Is there an easy way to load the code from a gem into a ScriptEngine, or am I just asking for headaches?
JRuby is a solid platform and integrates well with Java. But Rubygems do not integrate so well with Java build tools.
If any of the gems include native C code, then forget it, you can't use them from JRuby.
If all the gems (and all their dependencies) are pure Ruby, it is technically possible to use them from JRuby, but you will have headaches getting them packaged in JARs so that the JRuby runtime can find them.
Mostly I'd say no because of complexity. Although it's subjective, I'd personally rather take the time to re-write it anyway--you can make improvements and when you're done, you'll understand it better.
One option you might consider is splitting your application into two pieces, which interact using either something like pipes/files (or simply stdin and stdout) or some sort of an RPC mechanism. Whether an approach like this makes sense really depends on what the Ruby library does - creating the interface between the two applications might be more complex than actually reimplementing the stuff in Java.
I've reused Java code from JRuby, I don't see why this can't go both ways.
Another thought, can you run the Ruby code and then just tack on a web service or set of web services to call from the Java app? Sinatra makes it ridiculously simple to write a web service wrapper for ruby code. And Java has no shortage of tools to call Web Services.