I wonder if there is a AOT complier(s) for the Mac to compile Java apps into native executables, therefore eliminating the need for a JRE?
I have seen commercial examples for both Windows and Linux but haven't been able to find anything for the Mac, other than the opensource GCJ which has limited success with some of the poplar java libraries.
A native executable for the Mac would rid it of the JRE and, possibly, allow it to be signed allowing Java developed applications to possibly be accepted into the app store.
Install4J can compile your Java into a native OS X application but the system still should have JRE installed. Install4J just creates a wrapper for a JRE call.
You can use the Avian JVM for this. (Wikipedia article).
You can compile your application to a standalone executable and it supports different class libraries: openjdk, the Android class library implementation (even if you are not running on Android), and a custom class library that is very limited (basically they add methods to it as the authors need APIs to run their own applications).
In the README in the code repository there is a description how to embed the VM and generate a "boot" C++ program that will run your application and refer to the section "bootimage" if you want to AOT compile all the methods and generate a binary image obviating the need for JIT compilation at runtime.
Without the boot image, you can ship the jar files and a executable that will "start" them (the executable will embed the virtual machine). With the boot image, the jar files will additionally be pre-compiled to native code.
On the other hand, if you just need a managed language/platform, you can also use .NET/Mono AOT. See the mkbundle tool included with Mono 2.x.
Related
In addition to developing classic services on Spring Boot, I want to know Java with it environment better.
When I began to study portability, I came across such concepts as custom JRE (jlink, jmods) and native image (GraalVM, Liberica NIC).
As I understand :
Custom JRE for creating distribution folder with executable file. In folder only necessary dependencies. It arrived in Java 9
Native image for creating executable all in one JAR
Which of them should be used in which cases?
First of all, you should know what a JRE (Java runtime environment) is. Basically, it includes everything required to run Java applications that are already built. A JDK (Java Development Kit) is a superset of a JRE, adding the tools for developing Java applications.
With jlink, you can create JRE images. This means you are creating a Java installation that is capable of running your Java program. This can be done in a way so it only contains the necessary modules. jpackage allows you to create an installer for such a JRE.
On the other hand, a native image is a version of your code that's compiled and optimized for a specific target platform. Typically, it's a single executable file that runs your code. When creating a native image, it takes your application and converts (compiles) it to a platform specific executable (unlike jlink which creates a JRE that is able run your "normal" JAR).
Native-image does not generate a JAR but an ELF/EXE file which can be executed on your device without a Java installation while jlink just creates a (minimal) Java installation capable of running your application.
It should be noted that native-image comes with a few limitations. For example, remote class loading is not possible and if you use Reflection, you need to specify what to reflectively access at compile-time.
I am writing an application in Java. Does a Java SDK have to be installed to run the application from the command line? If so, can I package the SDK with the application to be installed when installing the application?
From Java 9 onwards you can use jlink to produce a custom JRE for your application. The JRE includes a copy of the java command and (only) the libraries / classes that your application needs. It will be platform specific.
From Java 14 onwards, you can use jpackage to produce (platform specific) native executables for Java applications.
There are also 3rd-party tools that can generate executables, and third party installer generators that (in some cases) can install Java for the end user.
Note: if you take the approach of distributing your application as a self-contained JRE or native executable, the user no longer has the option of updating their Java to address security related issues. It becomes your problem / responsibility ... as the supplier of the software ... to make available in a timely fashion application updates that incorporate the new Java releases with important security patches.
If you use something like GraalVM to compile a native binary, then there is nothing more you should need for a simple application (meaning, nothing is tried to dynamically load classes at runtime with reflection)
Other than that, the Java JRE is required, and can be included as part of an application package; for example, IntelliJ or Eclipse IDE come with their own JRE.
Thanks everyone for your input.
After doing more research I found that by using a jdk greater than 8.?, it is possible to bundle everything an application needs in the deployment process.
I have JRE 1.7 installed on my system. Due to some admin issues I don't have JDK on my system. is there any way I can develop Java programs with JRE only?
No you can't develop java programs only with JRE
You will need JDK for compiling your programs.JRE provides only runtime environment,but JDK is something you will need to compile your code to make them executable by your JRE.You will need javac for compiling your code which is present in JDK.
However for resolving the issue of admin rights you are having, you can download and install eclipse which has its own built in compiler.
You need some program which compiles your sources, but that doesn't neccessarily have to be the JDK.
For example you can download Eclipse which only requires a JRE, it has it's own compiler (built-in) and you can develop with that. Eclipse does not require any admin priviliges, it's a zip file which you can download and extract.
You need to compile them in order to develop and that is why you need jdk
You can't develop any Java application since you need JDK(Java Development Kit) to compile your code. JRE(Java Runtime Environment) provides run time environment only. You can run your compiled code in JRE.
the answer is somehow "yes,but..."
java source code execution procedure is split into 2 steps :
1)compiling the source code into a byte-code,thus generating the .class file
2)interpreting the VM specific instructions from the .class file into native instructions
.java----javac---->.class----java---->native code
needless to mention that the "javac" , the compiler of the java source code is in not part of the JRE!
so in order to develop java programs without JDK you have to skip the first step and keep using exclusively the "java" tool,thus dealing directly with byte-code !
in some extent and if you're acquainted with the JVM internals,it's possible to write some lines of byte-code using hex or text editors and then running the .class file;but you will not go further then that specially when it comes to creating complex applications as this require super-human capabilities :that's a highly daunting task .
nevertheless,todays java frameworks almost all use direct byte-code manipulation and tools like the asm framework or javassit
javassist does not require the JDK and you can generate a class from scratch and then compile/run it
java -classpath .:javassist-x.x.jar test "some arguments"
(no need to compile classes)
but again,that is only for restricted use and in order to develop java applications you have to use some JDK...
finally,you have to strive to acquire full control upon what is running in you machine;recent frameworks are resource-greedy and needs a huge amount of resources(disk space,memory...) and many tools and framworks require full control,i mean administrator right : for instance i remember that once a time borland delphi refused to start and i had to give it full access rights to start...
I request you to resolve admin rights. Else I have two options for you.
1) You cannot do anything without Java Development Kit.
2)You can install a IDE to code Java which makes your work in the current situation simpler. Use Eclipse or NetBeans. I would recommend Eclipse to you anyway. You can download eclipse from this link https://www.eclipse.org/downloads/
Try downloading JDK from this http://www.oracle.com/technetwork/java/javase/overview/index-jsp-138218.html.
Hope this helps you.
JDK is needed to compile your java file into class file. And JRE will execute the generated class file and provides the output.
If you have admin problems in your m/c then you can install the JDK in some other m/c and take the class files into your system and execute them.
Eclipse includes its own compiler and doesn't depend on the JDK compiler. But indeed, the JRE is just the runtime environment and doesn't include the compiler or other development tools.
Do you need this to do you job or not? If it's your job, you should have access or they should install it. If you don't have access because it's not your job, I suggest installing the JDK at home (or on a laptop you can take with you)
Due to some admin issues I don't have JDK on my system.
Install it in your home directory or another directory you can write to. Your admins can't prevent you from installing the JDK if you have enough disk space.
JRE is not just sufficient, without compiling the code for that you need Jdk which have compiler to compile the code.
I am getting this weird error when trying to run my Java program that I created as well as Jet Control Panel and JetPack 2. I have tried to run it on different computers with the same result.
In the manual page on configuring the JET Runtime, there is a section about system files shipped with JetPackII, which tells you that JET includes its own copy of the Java runtime libraries.
The error message is telling you that the Java Runtime that is packaged with JET is an expired evaluation version. That indicates that your version of JET is an evaluation version that has expired.
There are several ways to solve this error:
Pay the licensing fee
Get a free license for non-commercial use
Try to install another 90-day evaluation copy
Find another way to package your software
Background info for the drive-by reader, from the Excelsior JET User's Guide:
Excelsior JET is a toolkit and complete runtime environment for optimizing, deploying and running applications written in the Java programming language.
Maybe you could try to re-install the java runtime environment(jre) and then export it again. Did you try running it without putting it in an exe?
When compiled, most Java applications wind up as a series of .classfiles (containing bytecode) that are then archived into a .jar (java archive) file. This JAR file is actually a zip-format file that corresponds to certain layout and compression specifications. In order to be run, that JAR file must be fed into a Java Runtime Environment (JRE), which contains libraries as well as a virtual machine (JVM) and is typically downloaded straight from Oracle's servers.
Unlike a jar file, an exe file contains code that Windows can run natively without a JRE. By outputting an .exe file, your IDE is doing one of two things:
Adding a "stub" that finds a JRE that the user already installed, and then feeding the rest of the application packaged as Java bytecode in that exe file into it. If a JRE cannot be found, the program fails. An example would be the possibly-defunct JSmooth library.
Packaging the application with an entire Java Runtime Environment itself, which allows it to execute the Java bytecode regardless of what is already installed on the user's system. You may have to purchase a license to redistribute the JRE (which may or may not be Oracle's official JRE) alongside your application. This is likely what's happening to you here.
To help confirm that this is the case, post the name of the IDE you're using, and inspect the choices under your exe-generation command regarding redistribution, licenses, runtimes, and JREs/JVMs.
StackOverflow does have some existing answers about "converting a Java program into a .exe file", which you may find helpful for context.
I am working on an application called Enchanting. The application, based on Scratch, emits Java source code and compiles it for uploading onto LEGO Mindstorms NXT Robots.
While the application is very early, users have a hard time installing it.
Right now Windows users have to:
download and install a Java Developer Kit
download and install LeJOS (a java library for the NXT)
possibly tweak environment variables
then they can download, install, and run Enchanting itself
If I could provide an installer that would include the JDK, and LeJOS, I could figure out the environment variables at run time, and the process becomes:
Download, install, and run Enchanting
Is there a way to redistribute a JDK?
(Incidentally, Processing (a simplified text-based programming environment) seems to offer a version that comes with the JDK, so it appears that there is a legitimate way to do so).
Addendum: I would like a Windows user who does not have java installed to be able to run a single .exe file to install the JDK, LeJOS, and Enchanting.
The information regarding redistribution is here for Java 10 JDK and here for Java 8 JDK. Currently Java 8's is substantially more detailed than Java 10's.
and you can use PackJacket, to package all the files you need and create an installer.
Assuming you satisfy all the legal terms required to distribute stuff, you can use izpack to install all the prerequisites, including a JDK/JVM and configuration of environment variables.
Quite a number of IBM Eclipse based tools have JDKs with them.
Or you could just emit bytecode directly. You could bundle a much smaller (than the JDK) JVM dynamic language then use it to compile to bytecode or use libraries made for that purpose.
(I got the following from the Projects using Kawa page)
App Inventor for Android uses Kawa to translate its visual blocks language.
...The Nice compiler (nicec) uses Kawa's gnu.expr and gnu.bytecode packages to generate Java bytecode. ...
It's this last one is the one that uses the Kawa language framework to generate bytecode.
Don't forget about Groovy, Jython, Clojure, and Ruby. Interesting fact about Groovy, the interpreter can compile Java code since Groovy is (more or less) a superset of Java.