Here is my question i installed Java Plugin for Chrome it does mean i have installed java in my machine...And after installing this plugin can i run below command
java -jar myfile.jar
through a batch file or i have to install java in my machine and setup class-path then it should work?
If i will install Java browser plugin it automatically installed java in my machine and setup path as well.
Its hard for me t understand the situation how it works. Can anyone help me on this?
The JRE is the Java Runtime Environment, i.e. the software you need to interpret and execute Java class files. The Java browser plugin is the bridge between the JRE and the browser, used to run Java classes of applets embedded in HTML.
You can check the Java plugin of Chrome browser in this link.
The plugin is bundled with the JRE, and runs inside a browser, allowing Java code to run inside the browser process on the client. The main entry point class must be written as an Applet when the plugin is used, but all the Java code it calls can be just regular Java.
There are limitations when running Java code with the Java plugin for security reasons. All code shall run within sandbox with limited access to the file system and such.
Also as the plugin check for installed JRE version at your machine, that means you do have JRE.
You can install as many JDKs as you like. Just put them in different folders.
The one you refer to on the path is your choice - but presumably you'd choose the one that you want to use whenever you type "java ...." commands at the command line. In the absence of any other factors you should probably set this to be your most recent JDK version.
Note that your IDE may support multiple JDKs, for example Eclipse has "Preferences / Java / Installed JREs" where you can set up multiple JDKs/JREs for use with Eclipse
Please first check your machine contains java (jdk or jre)
java -version -- if you get a valid output then you have java in your machine.
in order to run java -jar myfile.jar , you should install java (jre or jdk) in your machine and class path set to the relevant location. To run this you should install jdk or jre in your machine. Most program only need the JRE (Java Runtime Environment) but some programs need the Compiler at runtime in which case you need the JDK.
Please refer this link to find out How to set class path .
Then you will be able to run your command.
Related
I am getting an error when trying to run a .java file as a Java Application and I get the following error:
Unbound classpath container: 'JRE System Library [JavaSE-14]' in project <project_name>
I tried to change the execution environment and for JavaSE12 and later versions there are no compatible JREs. (But for JavaSE11 the compatible JRE is java-11-openjdk-amd64)
I do not know what to do because the project I am working on doesn't work with old Java versions. How can I choose an environment for the latest Java versions?
Note: I am using Ubuntu 20.04 if that makes any difference.
tl;dr
I am not a Linux user, so I may not know best. But I suspect the simplest approach to running your .java file is to:
Obtain and install a JDK for Java 15 for Linux
Call java app on the command-line, passing the path to your .java file.
Backwards-compatibility is a priority for the Java team. Most any existing Java app should be able to run with the latest version of Java. There are exceptions, but they are very few.
JRE is passé
The JRE (Java Runtime Environment) was a subset of the JDK (Java Development Kit), omitting some of the programmer tools. The JRE as a separate product seems to be getting phased out.
Oracle and much of the Java community has shifted away from the idea of regular users having Java installed on their personal computers. Instead, apps should be delivered with a JVM specific to their host platform bundled within the app. This bundling of a JVM can be done using newer tools such as jlink and jpackage.
For more info, read:
Java Client Roadmap Update - Oracle (2020-05)
Java is still Free
Obtain a JDK
You said you have a .java file to execute. That file must first be compiled before it can be executed. The more recent versions of the java app can do both steps at the same time, compile & execute.
First download and install a JVM for your host platform.
Java 11 is the current long-term support (LTS) version. Java 15 is the latest release. You may want to read about the six-month release cadence for Java.
You have a bounty of vendor choices providing implementations of Java. Here is a graphic flowchart I made to assist in choosing a vendor.
If the steps shown here are overwhelming, I suggest either:
Using apt-get or similar package installer to obtain a build of OpenJDK for Ubuntu. I am not a Linux-user, so I do not know the details.
Head over to AdoptOpenJDK to download an installer for Linux.
Some motivations to consider in selecting a vendor.
Compile & run your app
Once your JDK is installed, on a console (such as Terminal.app in macOS), run something like the following. The java command should both compile and execute your .java file, if that single file makes up your entire app.
java /path/to/some/folder/MyJavaApp.java
We have deployed a Java based application for MacOS and Windows. We have now the issue that some users don't have Java installed and seem to be unable to figure out the error message and install Java on their own. This is only the problem for MacOS users, as we used Lauch4J for Windows, which redirects directly to Oracle in case Java is not yet installed. Is there any possibility to do this also for MacOS?
The alternative would be to ship the application directly with JRE or make it runnable without JRE at all. What are the alternatives and which is the easiest?
Thanks in advance!
It's not that you don't need JRE it's that you need to package the application with it. Look into Launch4j and jpackage or javapacker for java 8.
To tell the truth, I am quite confused on all these terms (JDK/JRE/Java SDK). I am not sure what each one does.
When I first started doing simple java examples in eclipse, I am pretty sure I only had the JRE, which I believed was the default java installer regular users use to be able to run java programs/applets on their system.
However, now in class we are using Google Appengine, and this requires the JDK which I am guessing is the same as Java SDK. After wasting some time finding out that installing the JDK meant I also had to add java/bin to the environment variables to get javac -version to work in the command prompt I find that only the JDK has javac...
How were my early java programs working without having installed the JDK and therefore not having javac? And really the main question... What is the difference between the JRE and JDK, and when do you use each one?
Thank you :)
JRE = Java Runtime Environment - what you need to run programs/software that require Java or use libraries written in Java. For example, OpenOffice requires the Java Runtime Environment
JDK/Java SDK = Java Development Kit/Java Software Development Kit - what you need to write programs that require Java or use libraries written in Java. For example, if you were to write your own word-processing tool in Java.
java comes with the JRE because it launches the VM (virtual machine). It can take in class files which are files that have been compiled using the JDK.
The JDK comes with javac because that's what you need to compile your .java files into .class files that can then run on the JRE.
Eclipse has its own built-in compiler (called ecj), which is probably the reason you could get away with not having the JDK installed to use it. It does not use javac.
Google App Engine uses the javac that comes with the JDK.
What is the difference between the JRE and JDK and when do you use each one?
JRE: Java Runtime Environment. It is used to run Java programs only. As Chris Jester -Young mentioned, Eclipse had a built in compiler. That's why you just needed JRE ( to run eclipse )
If you ship a Java program, the only thing the client need to have is this runtime environment
JDK: Java Develpment Kit, this also includes a JRE inside, but additionally have other tools for program development such as the java compiler javac among many others.
If you want to create java program you should use this.
There's no way you used the JRE to compile Java programs. javac, the Java compiler, only comes with the JDK.
You may write Java programs with whatever text editor, you don't need anything special to do this.
You need the JRE to run Java programs. The JRE includes the Java Virtual Machine, needed to run already compiled Java programs.
You need the JDK to compile Java programs. So if you are a Java developer, you may want to only install the JDK since it comes with the tools needed to compile, in addition to the Java Virtual Machine.
'Sometimes you can develop with jre'
No. Never.
You develop with the Java Development Kit. You run with the Java Runtime Environment or Engine or whatever it's called.
I want to be able to deploy my Java application so that it will run on any target (even if the target doesn't have Java installed)
I'm told I must distribute the JRE with my application. Do I literally take a copy of the JRE folder for Windows and one for Linux and have a shell to execute both?
Or are there further steps?
I think the best way to do this is to use an installer.
BitRock, Install4j, etc...
The installer will take care to install the JRE if it doesn't exist on the machine.
Moreover the installers above are multi-platform.
I downloaded 'Eclipse IDE for Java EE Developers' for Linux from eclipse.org. I am able to write, compile and run Java programs. But I don't understand what JDK / JRE is being used.
If I start a new 'Java Project' I can choose which JRE to use, but if I choose for instance 'JavaSE-1.6' I still don't know what that is? Oracle? IBM? And I don't know where that JRE is in my file system.
Let's say I want to use that same JRE to execute my Java program from command line, how do I find the 'java' executable?
While you are in Eclipse:
Open Help -> About Eclipse
click on Installation Details
select the Tab Configuration
search for the entry
eclipse.vm=
there should be the path to the used JRE.
If you want to know where is Java located in you'r system, run it in terminal whereis java.
If you want to know which Java is using in you'r system, run it in terminal which java.
If you want to know what is Java version is using in default, run it in terminal java --version
If you want to know which JDK is using in Eclipse,Refer to Project->Properties->Java Compiler.
If you want to know which JRE is using in Eclipse,Refer to windows->preferences->Installed JREs
It is up to your configuration.
Go to Windows/Preferences, then check:
Java/Installed JREs and Java/Compiler/
You can also override your settings per project: project preferences, Java Compiler.
(this is too long for a comment)
Let say I want to use that same JRE to execute my Java program from
command line, how do I find the 'java' executable?
On Linux the java executable is the first executable named "java" found on your path.
For example:
... $ echo $PATH
/home/f/jdk1.6.0_33/bin:/usr/local/bin:/usr/bin:/bin
... $ which java
/home/f/jdk1.6.0_33/bin/java
You can install as many JRE/JDK as you want. You can even trivially create user accounts with Java (e.g. a user account for development) and users account without Java (e.g. a user account without Java that you'd use only for browsing the Web [see comment]).
If you try to launch Eclipse when the $PATH doesn't contain any Java executable and if you didn't install any JRE/JDK inside ~/eclipse/, then Eclipse shall complain and refuse to launch:
"A JRE or JDK must installed in order to launch Eclipse"
At that point and if you did install Java, you can simply add it to the $PATH and Eclipse shall launch:
... $ export PATH=~/jdk1.6.0_33/bin:$PATH
Eclipse gives you an option to select the JDK on per project basis as well as for All projects.
For All projects :
Windows ---> Preferences ---> Java Compiler ---> Compiler compliance level ---> Select the JDK you wish to work with.
For Specific projects :
Project ---> Properties ---> Java Compiler ---> Compiler compliance level ---> Select the JDK you wish to work with.
The settings for the specific project is given priority over the All project settings...