Is it possible to compile java
It's using aggressive ahead-of-time AOT optimizations to achieve good performance. Excelsior JET is a commercial Java to native code compiler. However, it was discontinued in May In fact it can produce faster code than compiling the code in advance as it can generate code optimised for the specific platform based on how the code is used at runtime.
The JVM is always involved even if a very high percentage is compiled to native code as you could load and run byte code dynamically.
Another possibility would be RoboVM. As of today, the project still seems somewhat alive contrary to some posts online claiming the project to be dead. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Can I compile Java to native code? Ask Question. Asked 11 years, 5 months ago. Active 1 year, 3 months ago.
Viewed 56k times. Improve this question. Jeremy Smyth HotSpot compiles bytecode to native code on the fly wherever a "hotspot" of execution path something that gets run a lot shows up, and it's very good at it.
But if you're looking to avoid requiring a JVM, yes, look at the gcj James pointed you to. Yet another reason is protection against Java decompilers. It was also designed to be platform Dependent in some way by compiling not to bytecodes but to C code. I don't understand why this question was closed by the moderators.
It seems perfectly clear to me. The time involved depends on the number of classes to compile and the type of hardware on your machine. There are options that allow you control over how the details of native compilation are handled. Argument Summary Table summarizes the ncomp arguments. If you are executing in the directory where the JAR file exists and you do not specify the -projectDir option, you may give only the name of the JAR file.
If you are executing in the directory where the ZIP file exists and you do not specify the -projectDir option, you may give only the name of the ZIP file. If you are executing in the directory where the classes file exists and you do not specify the -projectDir option, you may give only the name of the classes file.
See "Natively Compiling Specific Classes" for a description of a classes file. Previously compiled classes are not passed over. This is useful if you need to preserve resources when deploying.
See "lightweightDeployment" for more information. This option specifies the name of the deployment JAR file and its destination directory. If directory is not supplied, it stores the output JAR file into the project directory denoted by -projectDir.
The resulting deployment JAR can be deployed to any server using the deploync tool. If not specified, JServer Accelerator uses the directory that ncomp is invoked from as the project directory. This directory must exist; the tool will not create this directory for you.
If it does not exist, the current directory is used. Thus, JServer Accelerator compiles the new classes and adds them to the appropriate shared libraries. The deployment JAR file is updated. If you want to place the shared libraries on the server yourself, you can do so through the lightweightDeployment option. The lightweightDeployment option enables you to do your deployment in two stages:. Note: You need to have FilePermission to write to this directory. Deploy the lightweight deployment JAR file to the server using deploync.
Errors Any errors that occur during native compilation are printed to the screen. If an error is caught while natively compiling the designated classes, JServer Accelerator denotes these errors, abandons work on the current package, and continues its compilation task on the next package.
The native compilation continues for the rest of the packages. The package with the class that contained the error will not be natively compiled at all. That is, the JVM will not run these classes natively.
All the other natively compiled classes will continue to execute in native format. The Java class is invalid; that is, one of its references may not be found. Any Java class that is unresolved, JServer Accelerator will try to resolve it before natively compiling.
However, if the class cannot be resolved, it is ignored by JServer Accelerator. Possible errors for deployment of native compilation JAR file:. Native Compilation Usage Scenarios The following scenarios demonstrate how each of the options for the ncomp tool can be used:.
The JServer Accelerator then retrieves all of the designated classes from the server, natively compiles them into shared libraries--each library containing a single package of classes.
Assuming that the classes have already been loaded within the server, you execute the following command to natively compile all classes listed within a class designation file, such as the pubProject. If you change any of the classes within the class designation file and ask for recompilation, JServer Accelerator recompiles only the packages that contain the changed classes. It will not recompile all packages. Once tested, you may wish to natively compile the designated classes on another host than the test machine.
Once you transfer the designated class file to this platform, the classes in this file must be loaded into the database before native compilation can occur. The following loads the classes through loadjava and then executes native compilation for the class designation file-- pubProject.
If you want all classes within a class designation file to be recompiled--regardless of whether they were previously natively compiled--you execute ncomp with the - force option. You might want to use the - force option to ensure that all classes are compiled resulting in a deployment JAR file that can be deployed to other JServer databases. The following forces a recompilation of all Java classes within the class designation file-- pubProject.
The deployment JAR file contains the shared libraries for your classes and installation classes specified to these shared libraries.
It does not contain the original Java classes. Not quite directly answering the OP, but an perhaps an interesting aside. Java can be run in three modes:. It might be better to detect the operating system using System. That would let you choose to support more than one OS, but exclude others. It is now: GraalVM allows you to compile your programs ahead-of-time into a native executable. Take a look at native-image feature:. Related question: 'Can I compile Java to native code?
Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Learn more. Is it possible to compile Java into machine code? Not bytecode Ask Question. Asked 9 years, 9 months ago. Active 3 years, 1 month ago. Viewed 23k times. Can you have Java compiled straight into machine code? Improve this question.
Dan McGrath
0コメント