How do i configure eclipse to make use of different version of JDK - eclipse

I have three project running on eclipse i want to use JDK 1.4 for two project and JDK 1.6 for third project how do i do that?

You need:
first to declare the different JRE in your Eclipse: See "Eclipse - no Java (JRE) / (JDK) … no virtual machine…"
then to add the right JRE in your project settings (see this blog post for instance)
The default JRE is shown with a check mark and is used by new eclipse projects unless the project specifically overrides the value.
So the next step is to check which JRE the current project is using.
Right click the project and choose "properties".
Select "Java Build Path" and then click the tab labeled "Libraries". You should see an entry like "JRE System Library [version]".
To change the JRE version,
highlight the entry and click "Remove".
Then click "Add Library...". Choose "JRE System Library".
If you choose "Workspace Default", the project will use the JRe defined under "Windows -> Properties" as explained above.
You may also specify an alternate JRE located somewhere on your file system, or choose an embedded execution environment provided by Eclipse.

you can configure VM in eclipse.ini file.

Related

Tools jar does not exist Eclipse JAVA

The archive: C:/Java/jdk1.6.0_26-32/lib/tools.jar which is referenced by the classpath, does not exist.
This is the error I have when run Tomcat. There was no problem cleaning or publishing - only when i start the Tomcat server.
Now, I checked my folders and there is a tools.jar in file path C:\Java\jdk1.6.0_34\lib
What am i missing?
using jre6 and have jdk1.6.0_34 installed
I found this question trying to build my project using Ant in Eclipse, and I would get the same error message as above. The suggestions in #Parth's and other answers to edit the Installed JREs is the first step. What I also needed to run Ant successfully was
Right click on build.xml, select "Run As", select "Ant Build..." (note the ...)
Click on the JRE tab
Change the Runtime JRE to the same thing that you updated in the first stage, and press Apply. (That is, the runtime JRE as you specified by "Preferences" -> "Java" -> "Installed JREs", as in #Parth's answer.)
Otherwise it seems that Ant will still try to build with the old JRE that doesn't have tools.jar. Hope this helps someone.
Right click on your eclipse project, In Preferences go to Java > Installed JREs, select your JDK and click on Edit. In the new Dialog you can add external jars like tools.jar to your execution environment.
I found the solution to resolve this.
Go to Run Configurations > classpath and under User Enteries you will have tools.jar and its path would be pointing to the old folder. Remove that and click on "Add External Jars" to add the tools.jar from the new path. And that is it.
This worked for me on Eclipse:
Windows -> Preferences -> Select Java -> Select Installed JREs -> Add
-> Add your JDK -> Establish it as default -> Apply -> OK.
After this, I've to establish project related settings too:
Right click on your Project Name (in Project explorer ) -> Properties ->
Java Build Path -> Click on JRE System Libraries -> Edit ->
Select Workspace Default JRE (jdk included above)
Check your "run configurations" (Eclipse Menu Run -> Run Configurations ....) also, since therein the classpath may be wrong or has gotten obsolete.
Tomcat needs a full JDK/SDK to run but under C:/Java/jdk1.6.0_26-32/, you only have a JRE installed.
Cleaning and deploying is done by Eclipse, no Tomcat code is involved so this works.
You need to configure your environment so that Tomcat uses C:\Java\jdk1.6.0_34 as Java VM. Check the values of JAVA_HOME and the content of setenv.bat
Right click on project->Properties->Compiler->Configure workspace settings->go to configure->installed jre->give jdk path
In my case with using ANT build I had to change the setting
Add tools.jar in the below location.
Windows --> Preferences --> Ant --> Runtime --> Global Entries.
In my case the Tomcat server in Eclipse has been created under older JDK (just a few builds). My solution was to remove the sever and add it again (now using current JDK).
I had the same problem (I can reproduce it) and my solution sounds like the integration in Eclipse is really screwed up but I actually fixed it by starting Eclipse with the same JDK version.
Add/edit the following in your eclipse.ini (which is in the Eclipse directory):
-vm
path/to/jdk/bin
Where path/to/jdk/bin is the path to the JDK bin directory of the version you are using for ant/tomcat.
Note that tools.jar is NOT included in a JRE distribution.
If you are running Ant build file and getting this error in eclipse, then your eclipse is configured to use two differently named JRE's. i.e. One from the jre folder and another jre from inside the jdk's folder. Adding tools.jar may be a workaround but I used the JRE inside the JDK's folder(C:\Program Files\Java\jdk1.8.0_121). Inorder to change this,
Check in Installed JRE section which JRE is cheked(I had jdk1.8.0_121 checked and jre1.8.0_121 left unchecked).
Update your eclipse classpath by navigating to Window > Preferences > Java > Installed JRE > Execution Environments.
Now select the JavaSE-1.x on the left side and select the compatible JRE[perfect match]. Select the same JRE(jdk1.8.0_121) you had it checked above and click Ok. Optionally you can delete the JRE(jre1.8.0_121) which is unused to avoid confusion if it is not used in any other projects.
Now your project will build and you can run the Ant build files. Check the image below.
Try to add the tools.jar as an external JAR.
For eclipse,
Right click the project name and select Properties
Go to Java "Build Path"
Select tab "Libraries"
Click "Add External JARs"
Select the relevant .jar file from the file selection
I am not sure it applies to all situations, but if you right click Ant script and there is an item "External tools configuration" under "Run as" menu, select it, and go to JRE tab. As far as I can say, it may be configured independently from your project and point to the JRE, not JDK, in which case there would be missing tools.jar
I remove server (Tomcat 6.0) from window -> preferences -> server -> Runtime environment.
And add again. Then, I add my project to server again. The problem is destroyed.
If You are getting this error while running the ANT build then follow the below steps.
In the Eclipse go-to window-> preferences-> ANT-> RUNTIME
then select classpath tab then select Global Entries and add tools.jar as an external jar.
Run the ANT build.

adding jfxrt.jar to standard Eclipse build path

How can I convince eclipse to include jfxrt.jar into its standard build path by default in order to avoid editing it manually every time I change the JVM?
thanks!
The more convenient way is :
Go to > Window > Preferences > Installed JREs > Edit your jdk >1.7u7 location
Then click on "Add external Jar" and choose the jfxrt.jar provided by the Jdk.
All JavaFX classes will be available for all your projects , just by adding this custom Jdk
The pitfall is that you can't use Execution Environment because the jfxrt.jar has not been added into Eclipse jars definition of a Jdk.
You can add jfxrt.jar from Project -> Properties -> Java Build Path -> Libraries -> Add External Jars
Unfortunately, you need to do it for each project.

Unbound classpath container: 'JRE System Library [OSGi/Minimum-1.2]' in Eclipse Juno

For my class I imported code from an online source given to us by the professor and tried to run it in Eclipse Juno (i'm not sure if it makes a difference what version) And I got the error message "Unbound classpath container: 'JRE System Library [OSGi/Minimum-1.2]' in project 'cs112'" I researched several answers to this problem and tried multiple solutions including building a path and adding a library, which i named JRE, and setting the correct execution environment! What could I possibly be doing wrong? Please help!!
In the Preferences (Menu Window, Preferences), find "Java", "Installed JREs".
You should have at least one JRE, better a JDK available.
Then, in the same section, there's a sub-section "Execution Environments".
The project you're trying to use asks for "OSGi/Minimum-1.2". The "Execution Environments" preference section allows you to view and adjust how the available JREs are mapped to requested execution environments. If none of your JREs are listed as compatible with the requested environment, you may have to
Install a new JRE or JDK, for example a recent Java 1.7
and, this is important, tell Eclipse about that new JRE by adding it to the "Installed JREs". Select "Add" -> "Standard VM" -> Point to "jdk1.7.xxx".

Using Eclipse, how can i tell what version of ANT is being used?

Same as original question, using Eclipse, how can i tell what version of ANT it is configured to use?
In Eclipse Helios:
Open the Preferences dialog (Window -> Preferences)
Navigate to the Ant -> Runtime page
Expand the Ant Home Entries node on the Classpath tab
This shows the path used for Ant classpath, which also reveals ANT_HOME for Eclipse.
So by default in Helios you will have something like:
<ECLIPSE_ROOT>/plugins/org.apache.ant_1.7.1.v20100518-1145\lib\ant.jar
etc
On this same page, you can also change ANT_HOME to use a different version of Ant you have installed on your PC.
Create a build file and echo $ant.version
On Helios
create an empty build.xml
ctrl+space in the empty file and select the default build file template with 2 targets
in the target called "default" add <echo>${ant.version}</echo>
save the file
right click on the build.xml in the navigator
select run as ant build
In Eclipse Helios (version 3.6.2) the version of the various plug-in modules such as ANT can be determined in the following manner.
Select the Help -> "About Eclipse SDK" menu option
Click on the "Installation Details" button
Click on the "Plug-ins" Tab
The "Plug-in Name" column is where ANT can be found the version is in the next column.
There will probably be multiple references to ANT in the "Plug-in Name" column including
Ant Build Tool Core
Ant Launching support
Ant UI
Apache Ant
I believe the "Apache Ant" is the most relevant entry and the others deal with how ant integrates with eclipse.

how to restrict jdk api version in eclipse

I am using jdk1.6 in my eclipse build path. But i want to restrict the eclipse to show only those methods that is supported in jdk1.4.2. Is there anyway to do this.
Thanks.
Project properties -> Java build path -> Libraries tab.
Select your JDK/JRE, click Edit
Select "Execution environment", Select J2SE-1.4, click Finish, click OK
You might also want to set your JDK compliance level to 1.4, that's in Java Compiler in either project or workspace settings.