How to Attach Source or Javadoc in Eclipse for Any Jar File E.G. Javafx

How to attach source or JavaDoc in eclipse for any jar file e.g. JavaFX?

You can configure the Javadocs with downloading jar, basically javadocs will be referred directly from internet.

Complete steps:

  1. Open the Build Path page of the project (right click, properties,
    Java build path).
  2. Open the Libraries tab.
  3. Expand the node of the library in question (JavaFX).
  4. Select JavaDoc location and click edit.
  5. Enter the location to the file which contains the Javadoc.
    Specifically for the javaFX javadoc enter http://docs.oracle.com/javafx/2.0/api/

for offline javadocs, you can download from : http://www.oracle.com/technetwork/java/javase/documentation/java-se-7-doc-download-435117.html

After clicking Accept License Agreement you can download javafx-2_2_0-apidocs.zip

Eclipse: Attach source/javadoc to a library via a local property

I believe this would be better achieved through:

  • the creation of a linked folder combined with
  • the declaration of a linked resource

The linked resource defines a path variable which would be equals to /my/path/to/lib/src

Eclipse Linked Resources

The linked folder would refers to your linked resource

Linked Resources

(you can use a variable and not a fixed path, with the "Variable" button)

The variable is actually always local (to one's workspace), and will be modified through the Linked Resources preference screen.

The linked folder can also be... a linked file, thus allowing the reference of an archive through a relative path (relative to the variable).

Then this linked file (here a linked archive) can be associated to your classpathentry in the "source" attribute.


The problem with Linked Resources is they are local to the workspace, in the preferences.

You can export the preferences in a [myPrefs.epf] file, and then trim the exported file in order to leave only the lines containing pathvariable:

/instance/org.eclipse.core.resources/pathvariable.MY_DIRECTORY=/my/path/to/lib/src

Anyone can then import this special preference file, which will only affect the "Linked Resources" part.

That solution is not very satisfying, since the .epf preference file can not be loaded automatically in the project.

When I setup a project with a linked resources defining a path, I always leave a big README.txt at the root of my project, in order to incite the user of said project to define that same linked resources with his/her own fixed local path.

Several bugs are in progress to enhance this situation or around the Linked Resources topic.

Especially:

  • Exporting a project with linked resources
  • Relative paths without variables
  • Have linked resources relative to workspace paths
  • Would like to use path relative to workspace root

DevByStarlight mentions in the comments the project (not very active since Oct. 2011) workspacemechanic.

The Workspace Mechanic automates maintenance of your Eclipse environment by tweaking preferences, adding extension locations, and so on. You can use it to:

  • Create a consistent environment among groups as large as the entire company, your local team, or even among your own many workspaces
  • Save time setting up new workspaces
  • Create tasks that ensure your favorite new preferences are applied to all your current and future workspaces. (This is one of our favorite features!)

The key to the Workspace Mechanic's behavior is the Task.

A task describes a simple test and an action that, when run, changes the environment so the test will subsequently pass.

Tasks can come in many forms: preference files, Java classes, Groovy scripts and Eclipse extensions. You can easily define your own Tasks.

It comes with a collection of scripts:

  • workspace-mechanic
  • workspacemechanic-settings

Attach the Source in Eclipse of a jar

A .jar file usually only contains the .class files, not the .java files they were compiled from. That's why eclipse is telling you it doesn't know the source code of that class.

"Attaching" the source to a JAR means telling eclipse where the source code can be found. Of course, if you don't know yourself, that feature is of little help. Of course, you could try googling for the source code (or check wherever you got the JAR file from).

That said, you don't necessarily need the source to debug.

How to get Source jar files for JavaFX classes?

JDK8 ships with javafx-src.zip in it's root directory.

For more detail see the related answer to JavaFX source code not showing.

I don't use Eclipse, but I'm guessing if you use Java 8 with a recent version of e(fx)clipse, it will include simple keystoke navigation to JavaFX docs and sources from within the editor. If not, you could add a feature request for this against the e(fx)clipse project and in the meantime configure your JavaFX Eclipse projects manually to be aware of JavaFX docs and source (like you can currently do in Idea).

How do I add the Java API documentation to Eclipse?

Eclipse doesn't pull the tooltips from the javadoc location. It only uses the javadoc location to prepend to the link if you say open in browser, you need to download and attach the source for the JDK in order to get the tooltips. For all the JARs under the JRE you should have the following for the javadoc location: http://java.sun.com/javase/6/docs/api/. For resources.jar, rt.jar, jsse.jar, jce.jar and charsets.jar you should attach the source available here.

How to solve This element has no attached source and the Javadoc could not be found in the attached Javadoc?

This is for a jar on your classpath in Eclipse, where you have

  1. attached a javadoc zip which Eclipse for some reason dislikes.

  2. NOT attached a valid source jar.

The easiest way is to right-click the jar in question (in the referenced jars, not the physical jar) and choose Preferences -> Javadoc. Here give a correct location (zip/URL) to the correct javadoc. Remember to use the "Validate" button to ensure that it is correctly set up.

Attach the Java Source Code

Normally, if you have installed the JDK6u14, eclipse should detect it and declare it automatically in its "installed JRE" list.

If not, you can add that JDK through "Windows/Preferences": Java > Installed JREs:

Just point to the root directory of your JDK installation: it should include the sources of the JDK (src.zip), automatically detected and attached to rt.jar by eclipse.

Add JRE VM, from pic.dhe.ibm.com/infocenter/iadthelp/v8r0/topic/org.eclipse.jdt.doc.user/tasks/images/task-add_jre_std_vm.PNG

How do I import the javafx correctly into eclipse? (The import cannot be resolved)

To run JavaFX 11+ on Eclipse, you have to follow the documentation here: https://openjfx.io/openjfx-docs/#IDE-Eclipse.

If you are not using Maven/Gradle build tools:

  • Download the JavaFX 13 SDK from here
  • Create a JavaFX13 library with the JavaFX jars.
  • Add the VM arguments to your run configuration.

JavaDoc and Sources

To get javadoc and sources working, you shouldn't add a (very old) jfxrt.jar, that is from and old JavaFX version, so you will get mismatches because some changes in packages.

The proper way to do it, if you already have your JavaFX13 library is:

  • Edit the library (Eclipse -> Preferences -> Java -> Build Path -> User Libraries -> JavaFX13), and display all the jars included. If you display the content of any of these jars, you will probably see:

    Source attachment: (None)
    Javadoc location: (None)
    • Jar by jar, select Source attachment, press the Edit... button, select External location, and find the src.zip file under the lib folder of your local JavaFX SDK.

Source and Javadoc

  • Jar by jar, select Javadoc location, press the Edit... button, select Javadoc URL, and paste https://openjfx.io/javadoc/13/.

  • Apply and close, when done.

You should now get Javadoc when hovering any JavaFX class, and also access to source code when Ctrl+Click a JavaFX class.



Related Topics



Leave a reply



Submit