Is it, at least theoretically, possible to convert a Java application into native code that can be run by something else written in Java? One example of this could be a Minecraft Spigot server. You can code plugins and stick them in the plugins folder of the Spigot server. The server then runs and then runs the plugins which interact with the server. Would it be possible to compile it to native code? If so, how (Spigot plugins don't have a main method, which is why excelsior jet won't convert it; is there a way around that?)? And would the plugin interact normally with the Java server, considering that the Java server would have to interact with native code?
One additional question is since the native code ends up running in the JVM, is it any more secure than a normal Java application running in memory? What I mean is when you run a Java application, it's in memory and you can dump the bytecode. Would the native code be any different than if it weren't native?
Am I thinking about any of this wrong? I ask that you also include any references or articles in your answers.
EDIT: When I'm talking about converting Java to native code, I am talking about using something like Excelsior Jet, explained here, which is essentially an AOT compiler which also has a JIT compiler for anything that needs to be run on the fly.
My specific questions are as follows:
- Can I convert something that needs to be run by something else written in Java?
- Will the converted plugin interact the same way with the server than if it weren't native code?
- Is the native code then run in the JVM? Or is it exclusively interacted with by the JVM?
- Can the bytecode then be dumped the same way that normal bytecode can be dumped? (example here or by modifying the OpenJDK)
- And, finally, would the native code be as easily reverse engineered or as readable as normal Java code?