Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
After releasing the module feature in Java and creating custom JRE, my question is what's really happen theoretically with custom JRE?
I know JRE (Java Runtime Environment) have inside JVM (Java Virtual Machine) and libraries that can run Java bytecode for environment (OS and CPU). So, if we use a Java custom JRE, what actually happens internally in guest PC and where is the JVM?
In Java 8 we download JRE and users can use our app, but after module feature the official JRE from Oracle is not released and the developer has to use custom JRE. So how could developer guess the OS or CPU architecture types (to send (Add) right JRE)? I don't use this feature right now, and I'm researching about it.
My question focused on what happened after compile code to java bytecode and send it for the user that have not jre and if my application can't start without jre and I need to use custom jre how can I know which type of machine running my code ? because in official jre the user download and use the java application but now the developer need to send custom jre that maybe not good for all users.
I think if knowing what happened here with custom jre(understanding the workflow) that can help me to use it.
The #StephenC answer is helpful and I need more details.
I'm (still) not sure that I understand what you are really asking. However, I will answer based on what I think you are asking.
I know a JRE has inside a JVM and libraries that can run Java bytecodes for environment (OS and CPU).
That is sort of correct, but not exactly.
The JVM is actually running thing. You get it when you run the java command. It isn't the java command itself.
Thus we can't literally say that the JVM is "inside" the JRE. It is a running process on the hardware.
So if we use java custom JRE What actually happened internal in guest PC and where it's the JVM?
It is essentially the same. The custom JRE includes a launcher (executable) that runs your application. When you run that launcher, you get a JVM running your Java application.
I Java 8 we can download a JRE and users can use it to run our apps.
Correct.
but after module feature the Official JRE from oracle not released and the developer have to use custom JRE.
You are conflating two things here:
It is true that Oracle (and OpenJDK) doesn't provide a (regular) JRE downloadable from Java 9 onwards. However:
There is nothing to stop you ... or your user from using a JDK distro instead.
There are other Java suppliers / vendors that continue to provide a JRE distro in one form or another.
You can create a custom JRE using the jlink tool.
... so how could developer guess the OS or CPU Architecture types.
If you are going to use jlink to create a custom JRE, you need to do it for each OS & CPU architecture that you support.
But as noted, you can still instruct the user to install a conventional JRE or JDK and continue to use ship your application as a JAR file, or a installer, or ...
Related
I want to make a Mac Application using Java code I wrote, and I want to make it that the person using it doesn't require Java to be installed on their own computer.
Is there a way to create a Mac Application so it can run on any mac, whether they have Java installed or not?
Either bundle a JVM or compile native
You have a choice of three ways to deliver a local Java-based app to a Mac user.
User installs a JDK or JRE on their machine. (Or I.T. sysadmin person does so.)
App comes bundled with a JVM for a specific OS and specific chip architecture.
App is compiled to native code for a specific OS and specific chip architecture.
Install JDK/JRE
In a controlled environment such as a corporation or school, it may be practical to install a JDK or JRE on every Mac. If you are writing JavaFX apps, you could install an edition of a JDK/JRE that comes with the OpenJFX libraries.
Your Java app can then execute by using the already-installed JVM.
By the way, in such a controlled environment, OpenWebStart is a way to deliver and launch a local Java app by using the convenience of a web browser.
In contrast, Oracle has abandoned the approach of expecting common consumer machines to come equipped with Java pre-installed. For details, see the Oracle white paper, Java Client Roadmap Update. So expecting individuals to have Java installed is not practical.
Bundle JDK/JRE
You can build your app in such a way as to include a JDK/JRE for a specific kind of machine, meaning a specific operating system and a specific chip architecture.
For Macs, that means you need one build for Macs with Intel (x86) chips, and another build for Macs with Apple Silicon (ARM, AArch64) chips. You would need to to either supply two separate versions of your app, one for each child, or perhaps a “fat binary” that includes two JDKs/JREs for both chips. The fat binary approach was supported by Apple (and its originator, NeXT Inc.) in previous chip transitions, but I’ve not verified is this is the case now in the Intel to Apple Silicon transition.
Modern tooling helps with embedding a JDK/JRE. See jlink and jpackage. See Packaging Tool User's Guide. As of Java 9, the Java Platform Module System enables including only the parts of the JDK/JRE actually used by your particular app. Unused parts are omitted, making for a smaller-sized final app artifact.
Compile native
The last way uses GraalVM technology to compile your code to native code specific to the targeted runtime machine. Instead of compiling to bytecode for a conventional JVM to interpret and optionally JIT-compile at runtime, full compilation to native machine language is performed when you build your app. This approach is cutting-edge, perhaps bleeding-edge. So research carefully and test thoroughly if you dare to consider this novel approach.
With both of the last two approaches, you have the option of distributing through the Apple App Store.
You don't need JDK to install on the client machine but as we know java converts the program into bytecode and a java compiler is needed to compile that bytecode into machine language you must install JRE on the client computer whether it is mac or windows or any other operating system
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have created an executable jar file and it works fine on double clicking on it. But there is this need to show output at the end of the execution. I used batch file with start xxx.jar command and it executes the jar but without console and output. I then used java -jar XXX.jar it does the job but the thing here is user may not be having jre installed.
Any suggestions?
start will ask windows to launch the file using the default launcher configured in your registry.
This, naturally, means nothing happens / an error occurs unless you've got a bizarre situation where the end user has actually installed a JVM, which you should not be relying on, and you'd have absolutely no idea whose JVM that is, or what version it is, or if it has been properly maintained. It will also use javaw.exe which is the one that doesn't show a console, and there is absolutely nothing you can do to change this.
I think you're misinformed - you want a solution that works if:
The user has installed a JDK or (obsolete) JRE themselves, and installed it in a way that double clicking jar files actually works, but...
did not update the PATH variable or otherwise ensured that java on the command line works
I don't think that covers many installations at all. The vast majority of deployments will either be 'the user did not install any java', in which case neither start nor java -jar is going to be a solution, or they installed it with java on the path, in which case java -jar in a batch file works fine.
Okay so how DO you deploy java apps
In modern times? With jlink to create a cut-down executable, and then you write your own installer which installs a JVM that you trust (the one jlink made, which is smaller, as all bits you don't need for the app in question aren't included in it), and thus results in the user being able to run your app without the need to 'find a java installation and install it'. This is unfortunately more difficult than it could be and requires that you use the module system.
Sounds like too much work, what's wrong with the old way?
The concept of the JRE (a java virtual machine that can run java applications, but without any development tools included) is dead. There is no more JRE; java8, now 7 years old, was the last time that was a thing, and the JRE that oracle ships is pretty much out of time: They have stopped supporting it, or will real soon now. That means you are asking your users to install software that will no longer receive security updates. That's why it's such a bad idea to do it like this. Sorry to be the bearer of bad news.
I have the following problem:
I wrote an application in java for my company. Now i have the problem that not every user has the jre installed on his pc. And due to company guidelines its not that easy to install it on every computer.
My question is: Can I write a batchfile which checks if the jre is already installed and if not copies the jre onto the computer? Would the jre work if I just copy it?
If you have another solution for my problem feel free to tell me.
Thank you for your answers
Bundling a Java desktop application with a JRE is in fact nowadays considered good practice. How exactly to do that depends on the target operating system. But there's usually no need to come up with an individual solution as Oracle provides instructions on how to achieve this in a standardized way.
This is what Oracle says about the basics of "Self-Contained Application Packaging":
Each self-contained application package includes the following items:
Application code, packaged into a set of JAR files, plus any other
application resources (data files, native libraries)
Copy of the JRE, to be used by this application only
Native launcher for the application, multiple launchers for a single
package are supported
Metadata, such as icons
They provide detailed instructions for Java 8 and Java 9 on how exactly to create the package for different operating systems.
I know it's possible to bundle the regular Oracle JRE in a Java application if you want to distribute it as a stand-alone application without requiring users to have the JRE already installed, but is it possible to do the same thing with OpenJDK?
This question is old, but an answer seems appropriate today (since this is new-ish)
The Java Platform Module System (Java 9+) supports this idea directly with the jlink tool. It's actually one of the specific, stated, goals of the system. And, to make it even better, a properly modularized software product will include only the necessary parts of the JRE and libraries, thereby remaining relatively small.
When deploying a Java application, can I assume that every computer has java, and so is able to run my application? I've just created a java app, which works on my computer, but my boss (who generally uses .NET) claims it doesn't work at all. Should I assume that this will happen often, or will most consumers have java?
I think it is better to NOT assume that all computers have JRE installed. Just like development practice you need to have a deployment strategy for your application.
Here are some of the questions you need to find answers to arrive at a better deployment strategy:
Which version of JRE is needed, what if the computers on which the application is run has an older version of JRE ?
What all platforms (windows, linux or both ) your application is going to be run ?
Is there a IT policy that ensures that a standard version of JRE is available on all the hosts ? In this case
you can make a valid assumption that all computers on which application is run has the JRE installed?
If you need a specific version of JRE which is not available on all the computers may be you have to bundle the
JRE along with your application.
I think that you should provide to your users a way to download/install the jre (probably a link) with a friendly message explaining the need to install it.
Java is widely use.
NOTE In example, following is an example of the applet tag:
<applet code=Applet1.class width="200" height="200">
Your browser does not support the <code>applet</code> tag.
</applet>
If you are deploying your application in a traditional way, there are some java application installers that handle it for you.
I hope it helps you.
You can also deploy a jre along with your application. Many 3rd party applications do this to ensure that the proper version of Java is available on the system. There are pros and cons with each approach.
You will want to refer to the license information about redistributing the jre contained in the jre folder ( e.g C:\Program Files (x86)\Java\jre6\README.txt - or wherever your install is ) to ensure you follow the proper procedures.
There are a number of solutions. You should not assume that everyone has Java installed. You can use web start for instance which will help with the setup. You can find some advice here.
More info about web start here.