I have a question that pops up occusionally.
I am trying to debug some jdk apis using eclipse.
I have tried:
1) Using the jre inside jdk (containing the jdk src) as the jre to use
2) Adding the jdk src as a separate project and add reference from my project to the jdk project.
I started debugging.
I got into the jdk code but only up to a certain point.
Then I got the "Attach Source" editor.
The part of code I am trying to debug is part of java's pkix apis that uses the JCE provider architecture.
So for example I do
Certificate generateCertificate(fin);//I go into the code
then I step into
return certFacSpi.engineGenerateCertificate(inStream);
And I get "Source Not Found Editor"
I see that the class called is:
public class sun.security.provider.X509Factory extends java.security.cert.CertificateFactorySpi
But I can not seem to find the package sun.security.provider in the jdk src.
Isn't all src available from SUN? Am I doing something wrong in my environment setup?
Any input is highly welcome
The full source code is distributed as separate jar file, but it's a little bit outdated (6u23): http://download.java.net/jdk6/source/
But you can also download the openjdk sources, that contain also the source of the sun specific classes.
Related
I have problem importing import "javafx.util.Pair" into my program.
after searching the net I've found this answer cannot resolve symbol javafx.application in IntelliJ Idea IDE and I've installed desired jar file but still I've problem to import.
this is what I face to when open java jdk.
I don't know the why the "jfxrt.jar" is different.
note the black arrow on the folder icon
open the File | Project Structure dialog, there under Platform Settings select SDKs and then your JDK 1.8. On the right you then see all the jars that make up the classpath to your SDK. Make sure that your jfxrt.jar is in that list, if not, you can add it by clicking the '+' button at the bottom.
Update May 2020
JavaFX is no longer part of the Oracle or OpenJDK default distributions. Instead it is available as a seperate library or module set.
For instructions on using JavaFX in your application, see the documentation at:
https://openjfx.io
For instructions on working with a modern JavaFX installation and Idea, also see the related question:
IntelliJ can't recognize JavaFX 11 with OpenJDK 11
You don't need to "install the desired jar" (whatever that means).
You don't need to do that for JavaFX. You should not do anything explicitly with jfxrt.jar either in the filesystem or by adding it to a project classpath. If doing something on the filesystem, that is especially bad as jfxrt.jar is not made to be standalone and requires related native libraries shipped with the JDK in order to work.
The JavaFX code should be part of the JDK installation you are using. Perhaps you are using a Java version below 8 or an OpenJDK implementation that does not include JavaFX. If so, then install the Oracle JDK 8+ and set idea to use it. Everything should just work then and all of related JavaFX imports will resolve.
Out of pure curiosity, I want to browse Java sources in Eclipse in order to benefit the ease of navigation and search.
When I import sources into a newly created project, I encounter thousands of errors, how do I correct these errors ?
The sources of the JDK are located in JDK_HOME/src.zip
Unzip this archive in the folder of your choice.
Create a new Java Project under Eclipse
Import the content of src.zip into your new project. The compiler will raise several errors.
First, you need to add JDK_HOME/lib/tools.jar to your build path. Into project properties, go to Build Path, libraries and add external Jar.
Second, you need to give access to normally restricted classes from the JDK. From the libraries pane, click the JRE system library and select Access rules. Set the resolution to accessible for the rule pattern */**. This gives access to all the classes in the JRE jars.
Finally, there are two classes that have been reported missing since JDK7 that you have to import manually. There are various solutions , the fastest for me is to download from OpenJDK repositories :
sun.awt.UNIXToolkit.java
sun.font.FontConfigManager.java
Enjoy browsing Java sources !
There is no reason to import the JDK sources as a project in Eclipse or try to compile them. If you have Eclipse pointed to a JDK (as opposed to a JRE), it will automatically pick up the src.zip that it finds there and show source when you browse to JDK classes.
Package Explorer, Project Explorer, Java Browsing, and other Java-oriented views show the packages and classes just as they were any other library/JAR. In Package Explorer they show up under JRE System Library.
In Java Browsing perspective, it looks like any other packages:
I wanted to start learning java but Eclipse is giving me some trouble.
First of all I'm a beginner with Java with little to no knowledge about it. I want to use 'JavaSe-1.7'. I have no clear reason to use it besides using the latest version. After downloading Eclipse (Eclipse IDE for Java Developers) I created a new Java project and selected 'use an execution eviorment JRE : JavaSE-1.7'. This directly popped the notification saying 'The default compiler compliance level for the current workspace is 1.6. The new project will use a project specific compiler compliance level of 1.7.'. I finished creating the project and started following some tutorials.
However I noticed directly I have 2 errors which dont explain anything or have a source. I ignored it and started typing and tried to import 'java.io.console' however it said 'The import java.io cannot be resolved' and I have no idea what is the cause of it neither how to fix this.
Would like some instructions into the right direction.
Thanks in advance
Check your Eclipse preferences: Java -> Installed JREs. The one that you're using should be marked and it should be a JDK not just a JRE.
Also check your project's build path: Right click on the project -> Properties -> Java Build Path
Check in the "libraries" folder whether the JRE System Library is present and if not add it using "Add library"->"JRE System Library" and then select the correct one (from an installed JDK).
You may not have your JDK/JRE set up correctly.
Check the following:
Did you install a JDK or just the JSE? The JDK is needed to compile .java files to .class files. Without it, you can only run java programs, not develop them. If not, download and install it from Oracle website.
Check in Eclipse, if you have the JRE installed there as well. You just need to specify the path to the installation. You can reach this screen via the "Window->Prefrences" menu. see this screenshot:
The message you receive about project specific compiler compliance level is not a problem, it just means that your workspace is set up to comply to java 1.6 but your project will comply to java 1.7 standards. Also, Java 7 in general is no problem whatsoever.
Paths may differ, especially if you're not running a *nix OS. Just point the location to where you installed your JDK.
sorry for bothering you all ..
I am trying to check out the SDK "Original" source code of sun java 1.7.0 (the src.zip file that come along with the complete package) in eclipse. I wanted to investigate the library src code for java.io.ObjectInputStream or java.util.ArrayList ....etc
But when I unzip the src.zip file and put it in Eclipse (under a new Java project) it shows me errors (attaching a snapshot of some errors ) ..Errors occurred during the compiling the source code lib
I am also attaching some of the errors screen shots ....... Errors in the code
Please pardon my ignorance and guide me to the correct path.
Many thanks
Regards
src.jar does only contain the source code of the public APIs and in certain places those delegate to 'internal' classes, e.g. com.sun.*.
If you want to look at the publicly available source code, you just have to install a JDK and point your Eclipse to the JDK instead of the JRE. Then it will automatically link to the source. Example screenshots reference IBM JDK (not JRE) 7 on Ubuntu.
EDIT: I forgot to mention that if you use OpenJDK via apt on Ubuntu (your screenshots look like this), you must explicitly install the source:
sudo apt-get install openjdk-6-source
Workspace preferences:
and source code for java.util.ArrayList
The icon on the editor tab indicates that this is just a link to the source file and not the source itself, you cannot edit it.
I have a code written in java. when i load it in eclipse it shows an error in the java code import line " The import com.sun.java.browser.plugin2 cannot be resolved"
import com.sun.java.browser.plugin2.*;
How can i fix this error..??
It's possible that it's to do with the version of Java you're building your project with, since the new applet class files were only introduced in Java 1.6 / 6.0. So, right click on your project on the left, go to Properties, Java Build Path, Libraries tab, and scroll down the list until you see JRE System Library. Note the version. If it reads less than 6.0 / 1.6, you're using an old version.
Click on JRE System Library, click Remove (make sure you have at least Java 1.6 installed!) then click Add Library. Select JRE System Library and select your Java version. If this isn't listed, go to Window > Preferences, Java > Installed JREs, click Add, and locate your JRE. Then repeat the same process and it should work.
(Edit: ignore what I said, the com.sun.* classes are hidden from the user. I don't think you can use it)
As far as I know, packages com.sun.* are implementation details of certain jvm and must not be used by application developers. They can be slightly different even between minor versions of jvm. Difference between major versions or jvms of different vendors can be sufficient. So IBM's and Sun's jvms have different structure of those packages. Only packages java.* and javax.* and org.* should be used. To fix this error correctly you must not use this package. To hack it around, you can try configure eclipse to use appropriate jvm though I don't know how to do it.
Update:
There's a FAQ entry about those packages. Thanks to R. Bemrose.
Did you type this in? Then the build path in incorrect. If not no sure what is going on.
Are you sure you are using the right JRE for your project? Like Java6?
See also JRE settings, and then make sure your project uses a Java6 JRE.
You have to add the plugin to the MANIFEST.MF dependency entry
Open MANIFEST.MF
Got to tab Dependencies
Add the plugin your referenced class is placed
You also have to be sure, that the package, the called class is lying, is added in the "Runtime" tab of the MANIFEST file.
EDIT:
The MANIFEST file you can find in the /META-INF directory