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...
Related
I have one RCP application and some other Java applications with different requirements on JVM version on the client desktop to be able to work.
One is 1.7 and two are 1.6, 1.5 requirements.
Depending on the Java binary directory order in the path variable, the Java version is selected (assume 1.7). So one application (which requires 1.7) is working and others are not.
Is there a way to ensure that all three will work?
or
Is there any approach that we can define a particular application should use a particular version by default independent of the Java bin directory of the path variable?
When you create an environment variable Java_Home, you basically tell the location where java executable is located and thus on executing java command, system can find it. What you can do is specify the full path to java.exe in a command and application will be executed using that Java executable version.
Eclipse has the concept of Execution environments and a means to assign JVM installation locations to certain execution environments.
Got to the preferences dialog (main menu > Window > Preferences) and register all that JRE and JDK installations that are needed under Java > Installed JREs.
Now you can them to the respective execution environments under Java > Installed JREs > Execution Environments.
After these settings are made, you can specify the desired execution environment for each Java project in your workspace. For Eclipse plug-in projects, open the MANIFEST.MF and choose the execution environment(s) on the Overview page. This change with update your build path accordingly.
For plain Java projects, you can change the execution environment under Project Properties > Java Build Path > Libraries.
You may need to adjust existing launch configurations to use the 'project execution environment'. For launch configurations of type Eclipse Application, the setting can be changed on the Main page.
Approach:
You can detect the java version by command java -version and parse it to get version information. now you can have check or block with popup message while invoking the application and inform you do not have compatible java, please go there and do this kind of something.
better you can have a drop down initially which have all java version information installed and on the basis of selection you can have above mentioned approach.
I am trying to run java application and I am getting following error,
Unable to find a javac compiler; com.sun.tools.javac.Main is not on
the classpath. Perhaps JAVA_HOME does not point to the JDK
I have gone through many SO questions and found solution is JAVA_HOME should be point to JDK, not JRE.
Then I have tried to print JAVA_HOME in command prompt,
I had set this JAVA_HOME from my computer->properties->env variables -> system vars as below,
I had also added new variable in eclipse using preferences as,
And finally I am still getting the same error. Whats wrong with JAVA_HOME ?
Update :
In eclipse-preferences-installed jres there is only one entry is present and which is jdk and selected,
And under project properties java build path-libraries there is JRE System Liberary [jdk1.8.0_31] is used.
Update 1 :
C:\Program Files\Java\jdk1.8.0_31 have folder named jre. Is that jre folder causing this issue ? Can I remove this folder ? Is there is any way to add only jdk liberary in project ?
Eclipse is an IDE and as such, it has (at least) two Java versions: The one which it uses itself to run (JAVA_HOME) and a JVM which it uses to run your application. The two don't need to be the same.
So to fix your problem, you need to look into Eclipse's preferences, specifically Installed JREs which gives you a list of Java VMs which Eclipse will use to run Java code from projects. My guess is that there will be several entries there and the default will be a JRE instead of a JDK.
Make sure you have a JDK in the list and then go to your project. In the project, you can select which Java VM to use under Java Build Path -> Libraries.
[EDIT]
Look closely at the last screenshot: You've configured Eclipse to use C:\Program Files\Java\jdk1.8.0_31\jre which means you've pointed it at the JRE inside of the JDK. Use C:\Program Files\Java\jdk1.8.0_31 instead (without the \jre at the end).
[EDIT 2] If you delete the jre folder, Java will stop working. Any JDK also contains a JRE. The JRE contains rt.jar with String.class and the like. The Java compiler is in tools.jar which is in the JDK.
If recreating the JRE entry in Eclipse doesn't help, you'll have to add it manually to the classpath.
You can use a variable ("Add Variable...") to make sure Eclipse updates the path when you switch to a new/different JRE. Try JAVA_HOME with the extension lib/tools.jar
In Eclipse click Run->External Tools->External Tools Configurations
Click JRE tab
Click Installed JREs... button
Click Add button (select Standard VM, where applicable)
Click Directory Button
Browse to your JDK version (not JRE) of your installed Java (eg: C:\Program Files\Java\jdk1.7.0_04)
Click Finish.
Re-run Ant script - have fun!
I faced the same issue while i was using ant from command prompt and the solution which I found is that you need to put tools.jar inside bin folder which is present inside apache ant folder.
For eg :-
D:\apache-ant-1.10.12-bin\lib
You will get tools.jar inside
C:\Program Files\Java\jdk1.8.0_211\lib
Please change the path based on your java installation path.
I have just installed Eclipse Indigo, and created a new project. It's telling me that the build path is not configured.
I have followed RighClick on the project -> Build Path -> Configure Build Path -> Libraries and there I found JRE System Library [jre1.8.0_31] and I don't understand why it doesn't recognize it.
Any help?
First of all you have to know some stuffs about JAVA. Java uses a JVM (Java virtual machine) wich is the JDK and need to be installed on your computer.
The JDK makes the JVM run and the JRE allow you to compile etc java class. (No need for both, just install the JRE)
see this page.
Then you'll have to configure a window GLOBAL VARIABLE. The JAVA_HOME var.
"1-Right click My Computer and select Properties.
2-On the Advanced tab, select Environment Variables, and then edit JAVA_HOME to point to where the JDK software is located".
This way Eclipse will be able to find the installed JRE.
Finally, in eclipse, check that it know the JRE.
And that's it. There is a lot of info over the web about this for more details.
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.
I recently had to migrate to a new machine and re-installed Eclipse.
At the moment, I need to generate JAXB classes from an xsd. I cannot quite remember what I installed, but in my old Eclipse I had the option -rightclick-generate-jaxb classes.
Who knows what I have to install/plug-in to get it back?
I was looking at installing Dali, which seems like it could be right, but I am pretty sure I did not install Dali last time. I also included the jaxb jars in my build path, as last time, so that should be ok.
I am using Eclipse 3.6 and Java SE 1.6.
If you don't have JavaEE:
Help>>Install New Software>>Works with:--All Available Sites--
Search for JAXB
Then select Web, XML, Java EE and OSGi Enterprise Development and install.
After you restart Eclipse you should see the generate option.
A simple fix for this problem - rather than worrying about adding additional plugins or installs - is to install Eclipse IDE for Java EE Developers rather than Eclipse Classic (both to be found here). This comes with the JAXB support and therefore provides the >Generate>Jaxb classes option.
The above methods may work, but actually the options comes from a plugin called Web Tools Platform which comes along with Eclipse IDE for Java EE Developers.
Don't worry about reinstalling eclipse or try out other methods. No matter what eclipse you use simply install this plugin by following the below procedure. You will get the "JAXB Classes" Option on click of "Generate" button.
Help --> Install New Software --> Add
Name : Web Tools Platform
Location : http://download.eclipse.org/webtools/repository/helios
Hint : In case if you are using a different version replace helios with your eclipse version name. I used it as luna. So the path looks like http://download.eclipse.org/webtools/repository/luna
And restart eclipse. Now you will have that option.
(I'm using IBM's Eclipse-based RAD, so I don't know whether this applies to raw Eclipse.)
Have a look at your project Facets (select project, rightClick->Properties, Project Facets) I have the option of selecting JAX/RS.
later: I've checked my plugins and by default I get Dali installed and it does contain some JAX/B-related stuff. I suspect you do need this.
After a lot of research here is what I have done to fix the issue.
Windows> Preferences> Java> InstalledJREs...make sure to point your jre to the jdk directory. I was pointing to JRE and as soon as I changed it to JDK, it started working.
Hope this will help you guys.
I installed this plugin
http://java.net/downloads/jaxb-workshop/IDE%20plugins/jaxbw-plugin.zip
i.e. unzip and copy to eclipse/plugin folder.
It adds an entry "JAXB 2.1 > Run XJC" to the context menu of *.xsd files.
So the menu's not really in the proper place, but it works.
In order to support the standard JAXB APIs in the IntelliJ IDEA Community Edition environment, you need to make some adjustments. One way to implement JAXB technology is to connect the xjc.exe utility included in the JDK toolkit. This utility can be launched at the command prompt, but it is advisable to configure the context menu:
In the Settings window, select Tools | External Tools and press the
"+" button.
In the Edit Toolbox dialog enter:
the name (Name :) of the new Generate JAXB Classes command;
the path to the xjc.exe utility (Program :), which should be selected on the particular computer in the file selection dialog(button "..." )`
parameters (Parameters :) which in our case will be as follows:
$ p $ FileFQPackage $ $ SourcepathEntry $ $ FilePath $
In order for the created command to work correctly, the schema file should be placed in a new package, which will then appear with the generated files.
In the settings window, Tools | External Tools - "Your command name" will appear.
All you need is to open your schema file and run the command.
you may download JAXB Eclipse Plug-In
jaxb eclipse plugin
I had the same issue while attempting to generate java classes from xsd file.
My installed Eclipse is:
Eclipse Java EE IDE for Web Developers
Version: Oxygen.3a Release (4.7.3a)
Build id: 20180405-1200
I solved it changing the workspace default JRE from JRE to JDK in Project Properties / Java Build Path / Libraries
This link describes how the problem arises:
https://www.youtube.com/watch?v=zgblFjA-5Ks
This link explains how to change the default JRE.
https://www.zkoss.org/wiki/Setting_Default_JRE_In_Eclipse
Hope this helps
If you're using Eclipse EE all you have to do is switch your running environment from JRE to JDK and that should fix it. Windows -> Preference -> Java -> Installed JRE -> Add - > (Choose Standard VM) Then Select JDK!
Then Execution Environments under Installed JRE select your JavaSE-1.8 or your version and also select JDK!