I am using Ubuntu 12.04(LTS). In my project in Eclipse I need to use the com.sun.tools.attach package. However, my JRE system library does not include the tools.jar file which contains the package.
I tried installing different JREs and JDKs for both Java 6 and 7. What I noticed is that some of them have the mentioned jar file in their libs folder but Eclipse still fails to include it in my classpath upon selection of the JRE. Referencing tools.jar directly solves the problem but since this is a shared project I am not allowed to modify the classpath and thus this is not a viable solution for me.
My friend is using a MAC with the same version of Eclipse and the default JRE and does not have this problem. What we found out is that for him tools.jar is part of classes.jar which is not the case in my setup (I don't have classes.jar whatsoever).
What do you think might be the source of this problem?
The issue is that the JDK contains the tools.jar file (neither of the JREs do).
It is easy to solve the problem, you have to specify the default runtime environment to use either for the project or for the whole workspace. Change that to any of the installed JDKs.
The easiest way is probably going to Window --> Preferences --> Java --> Installed JREs, and selecting the JDK instead of the JRE. All the projects use this setting by default.
I had exactly the same problem on Ubuntu 12.10 and in my case managed to solve it by adding a reference to the current Java binaries folder to my PATH variable.
PATH="$PATH:/usr/local/java/current/bin"
Or
PATH="$PATH:$JAVA_HOME/bin"
Just edit either .profile or .bash_profile in your /home/<user> folder and you should be fine. If these files doesn't exist just create one of them.
Note: make sure your are using JDK and not JRE
Related
In my installation of Eclipse IDE (Mars 4.5) it has not automatically linked rt.jar and jfxrt.jar to src.zip and javafx-src.zip. I know how to do this manually by browsing to the .zip files within the JDK installation.
What I want to know is if there is a way to ensure this happens automatically when installing Eclipse / Java. I'm pretty certain I know someone who didn't link to the source manually and it is linked on their installation.
For example, if you install the JDK before Eclipse, or vice-versa, does this make any difference?
Also, when you make the link, where abouts is the preference information stored on the file system - is it somewhere within the same folder that eclipse.exe exists?
To make sure that Eclipse is running in your JDK instead of a JRE (The JDK installation typically puts a JRE on the system executable path), you should always specify it via eclipse.ini. The -vm option described there tells Eclipse exactly what JVM you want it to run in.
Another option is to add the JDK to the Installed JREs section of your Eclipse preferences and set that as the default for all projects. The default JVM used for projects is the same as the one Eclipse itself runs in, so you don't necessarily need to do both.
Once you have the JDK set as the default JVM, you can open a project's Properties, select Java Build Path section, then look at the Libraries tab. You should see your JDK as the JRE System Library, including its rt.jar and corresponding source attachment. Like this:
Is it possible to use Eclipse variables like ${workspace_loc} or ${eclipse_home} for adding a JRE to Installed JREs in the Eclipse preferences?
No, you cannot use variables for that, neither in the JRE preferences nor the execution environment specifications. And don't look at the eclipse.ini as suggested in comments, the JVM running your IDE has nothing to do with the JRE used to compile your project.
That said, there is still another easy solution (which we use in our company): Just install a second copy of the end user JVM at a known fixed location for your developers, so you can use that fixed path in the JRE preference page.
If you fear that the two JRE copies (in your project and at the fixed location) get out of sync over time, then you could use an Ant based builder to your Eclipse project, which conditionally copies the JRE from the workspace to the outside known fixed location during the build. But honestly, it does not really matter if those 2 copies get out of sync. If your code was compiled using a 32 bit JRE, it will run on another 32 bit JRE deployed at your customer anyway, as long as they are byte code compatible. And you can set that explicitly in the Java compiler settings of your Java project.
I have two JRE in my system. One is 32-bit and the other one 64-bit. In Eclipse I can configure both and choose which one to use when running my application.
I'm wondering if I can do the same thing in Netbeans. I've tried to go to Project Properties, Libraries and then tried to configure a new JRE there, through Manage Platforms, but it doesn't accept the directory of my JRE. How should I proceed?
Be aware that I'm talking about JRE, and not JDK ;)
EDIT: I managed to make it work by downloading a new 32-bit JDK and selecting its directory. I still couldn't make it accept a JRE directory.
Whether or not you can run Netbeans with just the JRE depends on what bundle you have downloaded. In Netbeans 7 only C/C++ and PHP bundles can be run with the JRE.
Older versions of Netbeans include more languages under this JRE umbrella, but the principle is the same.
The JDK contains the JRE plus tools to debug and compile code, so if you're doing anything Java based apart from just running the IDE, netbeans depends on the JDK.
I am having two JRE / SDK in my development environment, however it was necessary in my situation to set JAVA_HOME to 1.4.2, this is causing my eclipse IDE to stop running as it required 1.6 and above.
May i know how i can modify eclipse ini or environment home to use my other 1.6 installation?
Please try the eclipse.ini entry above the varargs (the following two lines must be two lines in the eclipse.ini file)
-vm
C:\Java\JDK\1.5\bin\javaw.exe
Find the JVM
Right click the project in Package Explorer -> Configure Build Path
Add Library -> JRE System Library
Set JRE system library to JDK
Verify JDK is the reference library
From the menu in the top.. Proceed as follows--
Project-->Properties--> Java Build Path--> Libraries--> JRE System Library.
Now click Edit . Select Alternate JRE. Click Installed JRE. Provide path to your other JDK. Then FINISH.
That's it.
I was trying to compile a Grails application referencing third party JARs on Mac OSX. Although my system's JRE and JDK is set to Java 1.6 I always got a Compilation error: java.lang.UnsupportedClassVersionError: Bad version number in .class file
when accessing classes in the JAR. Also when testing an existing Grails app the default stats of the app where showing that it's running with Java 1.6. So I really didn't have more ideas than to try to change the Java settings in Eclipse - I thought that's stupid as I'm not using Eclipse for the devlopment of this application - but voila - now the compilation of my app on the command line works just fine!
Can anyone explain me what Eclipse is doing here behind the scenes?
I've had set the JAVA_HOME manually before with no effect.
The JDK (JAVA_HOME) used to launched eclipse is not necessarily the one used to compiled your project.
To see what JRE YOU y can select for your project, check the preferences
General > Java Installed JRE
By default, if you have not added any JRE, the only one declared will be the one used to launched eclipse (which can be defined in your eclipse.ini).
You can add any other JRE you want, including one compatible with your project.
After that, you will need to check in your project properties (or in the general preferences) what JRE is used, with what compliance level: