Cannot get content assist in Eclipse working with Guava - java

I have had problems getting Content Assist in Eclipse to work with Guava. This assist works fine for code which has source I have loaded into projects (such as JFreeChart), but I cannot find source code for Guava. I have tried putting all three jars into the build path (guava-14.0jar, guava-14.0-javadoc.jar, guava-14.0-sources.jar), and have pointed the Javadoc location to a folder on the hard-disk with guava-14.0-javadoc.jar. With any combination of these, I get "Note: This element has neither attached source nor attached Javadoc and hence no Javadoc can be found." from a hover. Any ideas?

In Eclipse, you have to point the Javadoc location to the guava-14.0-javadoc.jar file itself, and not to the folder containing it.
In your project properties, go to Java Build Path, tab Libraries, find the entry for the guava jar and click on the little triangle on the left to unroll the jar options. Click on "Javadoc Location" and chose the "Edit..." button. Then choose "Javadoc in archive" and "External file". Write the jar file path or use the Browse button to find the jar.
You don't need to put the javadoc and the source jar in the build path.

Related

No source attachment in Java

I am trying to use an external .jar file in my project. I have put that .jar file in my project's /lib folder, and I have referenced it in the build path. However, when I try to use it in code, I can't get the javadoc for it, nor I can see the actual code from the referenced classes. It says it has no source attachment. What is it meant by source attachment? I do have a javadoc folder that came with it, but when I attach it to my build path, it still reports it could not found the javadoc for the classes. Any ideas on that?
I want to be able to see the javadoc.
The .jar file is the generated packed classes of the java code. Some jars will come with java doc and code and others won't.
For recent Eclipse versions:
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. (Select Validate!)
For older Eclipse versions:
First: Navigate to the jar itself in the Eclipse project explorer (to the left) and try to open aclass of the jar. Then, you will see the warning that it has no source attachment, and a button to attach the source code.
Then, push the button, select "external folder" and then navigate to the folder with source you already have.
hope I got you right:
try to right-click the jar in the references jar tab and go to Preferences -> Javadoc.
choose the right location to the correct javadoc and press "Validate" afterwards
Jar files can be built with or without source code. It's normal for 3rd party applications to produce a binary jar and a source jar, but it isn't required. The message is telling you that it doesn't know where the source code is for the library you are using. It's been a long time since I've done this in eclipse, but there is a way in the project settings to point each library jar to the corresponding source location (which can be a jar, zip file or directory).
Here are a couple of references
Attach the Source in Eclipse of a jar
Attaching the source to a library in eclipse

Error "This element has no attached source and the Javadoc could not be found in the attached Javadoc."

In Eclipse plugin development, I'm importing packages via the MANIFEST.MF file. So I don't have a lib folder and no referenced libraries section.
I can't see the javadoc comments even for the most basic methods like String.format()
The warning I get is:
"This element has no attached source and the Javadoc could not be found in the attached Javadoc."
Also when I click on "Open Attached Javadoc In A Browser", I get a security warning which asks me if I really want to visit the webpage. If I confirm, I can see the javadoc in the browser.
You have selected a Java Runtime which doesn't contain sources. Check the preferences "Installed JREs" and make sure they include sources.
You can add the source code for referenced libraries. Go to Plug-in Dependencies, choose the jar you want and hit Ctrl+Enter (Properties) and add the path. For most libraries you can download a jar containing the source.

Eclipse Java Project - Open Declaration always opens class file instead of .java

I'm posting this query after doing lots of googling and trying out different options for last few days. Is there an easy way to attach source in Eclipse? is the closest answer I found to my question.
From above post, I tried all solutions but each time Eclipse is opening .class file instead of .java file.
Eclipse Details:
Kepler Service Release 2
Build id:20140224-0627
Please let me know if this is a bug with Eclipse or if I am missing something.
If you are using Maven, try this:
Double click on your project in eclipse -> Maven -> Enable Workspace Resolution
This is most likely because Eclipse actually use the class file for declaring the item you have requested the declaration for, and not the source file you think it should be using.
The typical reason for this is if you have a jar file containing previously compiled classes on your build path before (or instead) of the project containing the source you want. This is very rarely desirable as it can take quite a while to discover that your edits do not take effect.
Examine your build path carefully and ensure it is as you want it to be.
Maven is likely supplying a Classpath Container to your project, and generating entries for the Java Build Path based on the pom.xml contents (the JRE System Library is another example of this). Its entries will not have source attachment unless the container decides it will, which is why the Installed JREs preference page offers to let you set Source Attachments. If the pom.xml has something like that, see if you can use it. If not, see if you can configure the Maven container from its context menu. Otherwise, you may simply be stuck.
I had this same problem: when I pressed F3 or tried to open Declaration (after right click) for any element, it took me to the bytecode .class file.
My solution:
I went to the project in Project Explorer:
right click on project name->Properties
Then in Porject Properties window,
Java Build Path->"Order and Export" tab
There I selected the folder with the .java files (source code), which was below the folder having the .class files -in my case "JRE System Library [java-11-openjdk-amd64]", and pressed 'Top' button on the right frame. Then the folder with source files moved to the top.
Finally, pressed "Apply and Close" button.
That solved my problem forever and ever.
The folder
I installed a plug-in which allows me to download the sources for a maven project.
I'm not by my develop machine right now, but I think it was this:
http://marketplace.eclipse.org/content/m2e-dynamic-sources-lookup#.U8gjGWIaySM
With this, you can select a project an have maven download the sources and make then available when you navigate the code in Eclipse. All without "leaving" Eclipse.
Check into your project modules the Java Build Path, look inside the Source tab and verify if you have "Allow output folders for source folders" checkbox flagged; in this case you just need to uncheck it and you will be able to see again the right source from java files.
This is related to the Call Hierarchy in Eclipse IDE.
If you are in a situation, where you're seeing duplicate methods inside the call hierarchy showing Members calling 'myMethod(...)', double-clicking on one of the listed methods may open the .class file instead of the .java file.
When this happens, the solution is to set the search scope in the call hierarchy to Project instead of Workspace.
After setting the search scope, you won't be seeing duplicate methods listed in the call hierarchy, and double-clicking on the listed methods will only open the .java files.
(Using Eclipse DevStyle Dark Theme)

Attach the Source in Eclipse of a jar

I added a Student.jar into my Build Path in my eclipse like this-
Right click on the project->BuildPath->Configure Build
Path->Libraries->Add External Jars
There is one class named StudentTest in Student.jar file. When I was debugging my code in eclipse, I stepped into that StudentTest class in the Student.jar.
And after that eclipse shows me like this-
The JAR file S:\some_location\Student.jar has no source attachment.
You can attach the source by clicking Attach Source below
Now I am not sure how should I attach the source in my eclipse. And from where? Can anyone provide me step by step what I need to do.
Update:-
I tried unzipping the Student.jar and I got Student folder. And after that I tried pointing the source to Student folder But still I am not able to see the class properly so that I can debug it properly, it shows the same above behavior.
Use Java Source Attacher !
It does what eclipse should do - a right click context menu that says "Attach Java Source.
It automatically downloads the source for you and attaches it. I've only hit a couple libraries it doesn't know about and when that happens it lets you contribute the url back to the community so no one else will have a problem with that library.
Eclipse is showing no source found because there is no source available . Your jar only has the compiled classes.
You need to import the project from jar and add the Project as dependency .
Other option is to go to the
Go to Properties (for the Project) -> Java Build Path -> Libraries , select your jar file and click on the source , there will be option to attach the source and Javadocs.
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.
This worked for me for Eclipse-Luna:
Right Click on the *.jar in the Referenced Libraries folder under your project, then click on Properties
Use the Java Source Attachment page to point to the Workspace location or the External location to the source code of that jar.
Go back in to where you added the jar. I believe its the libraries tab, I don't have Eclipse open but that sounds right. to the left of the jar file you added there should be an arrow pointing right, click that and 3 or 4 options expand, one of them being the source file of the library. Click on that and click edit(I think you can also double click it) then locate the file or folder on your hard disk, you probably have to click apply or okay and you're good to go, same with javadoc and i think the last one is native libraries. I don't pay much attention when I'm in there anymore if you couldn't tell. That's what you were asking, right?
I Know it is pretty late but it will be helpful for the other user, as we can do Job using three ways... as below 1)1. Atttach your source code using i.e, Right click on the project then properties --> Java build path--> attach your source in the source tab or you can remove jar file and attach the source in the libraries tab
2. Using eclipse source Analyzer In the eclipse market you can download the plugin java source analyzer which is used to attach the open source jar file's source code. we can achieve it after installing the plugin, by right click on the open source jar and select the attach source option.
3. Using Jadclipse in eclipse you can do it last not the least, you can achieve the decompile your code using this plugin. it is similar way you can download the plugin from the eclipse market place and install in your eclipse.
in jadclipse view you can see your .class file to decomplile source format note here you cannot see the comment and hidden things I think in your scenario you can use the option one and option three, I prefer option three only if i want to the source code not for the debug the code. else i ll code the option 1, as i have the source already available with.
Simply import the package of the required source class in your code from jar.
You can find jar's sub packages in
Eclipse -- YourProject --> Referenced libraries --> yourJars --> Packages --> Clases
Like-- I was troubling with the mysql connector jar issue
"the source attachment does not contain the source"
by giving the path of source folder it display this statement
The source attachment does not contain the source for the file StatementImpl.class
Then I just import the package of mysql connector jar which contain the required class:
import com.mysql.jdbc.*;
Then program is working fine.
I faced the same issue and solved using the below steps. Go to Windows->preferences->Editors->File Associations
Here click on Add
then type .class
click on OK
again click on Add
then type .classwithoughtsource
click on OK
Now you will be able to see JadClipse option under Java section in Windows->Preferences
Please provide the path of jad.exe file as shown below.
Path for Decompiler-C:\Users\ahr\Documents\eclipse-jee-galileo-SR2-win32\jad.exe
Directory for temporary Files-C:\Users\ahr.net.sf.jadclipse
click on Apply
Now you should be able to see the classfiles in proper format.
It is quite possible, just go to the jar in the Build Path and choose to attach a source just like follow.
Download JDEclipse from http://java-decompiler.github.io/
Follow the installation steps
If you still didn't find the source, right click on the jar file and select "Attach Library Source" option from the project folder, as you can see below.
I am using project is not Spring or spring boot based application.
I have multiple subprojects and they are nested one within another.
The answers shown here supports on first level of subproject.
If I added another sub project for source code attachement, it is not allowing me saying folder already exists error.
Looks like eclipse is out dated IDE. I am using the latest version of Eclipse version 2015-2019.
It is killing all my time.
My intension is run the application in debug mode navigate through the sub projects which are added as external dependencies (non modifiable).
I have faced same problem and resolved it by using following scenario.
First we have to determine which jar file's source code we want along with version number. For Example "Spring Core" » "4.0.6.RELEASE"
open https://mvnrepository.com/ and search file with name "Spring Core" » "4.0.6.RELEASE".
Now Maven repository will show the the details of that jar file.
In that details there is one option "View All" just click on that.
Then we will navigate to URL "https://repo1.maven.org/maven2/org/springframework/spring-core/4.0.6.RELEASE/".
there so many options so select and download "spring-core-4.0.6.RELEASE-sources.jar" in our our system and attach same jar file as a source attachment in eclipse.
Try removing the breakpoints. :)

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

Presently I'm working with JavaFX. Whenever I hover over a method of JavaFX its gives me the following error:
'Note: This element neither has attached source nor attached Javadoc and hence no Javadoc could be found'
How should I resolve this? How can I attach the javadoc or source so that I could see the description of the methods?
Download jar file containing the JavaDocs.
Open the Build Path page of the project (right click, properties, Java build path).
Open the Libraries tab.
Expand the node of the library in question (JavaFX).
Select JavaDoc location and click edit.
Enter the location to the file which contains the Javadoc (the one you just downloaded).
You can configure the Javadocs with downloading jar, basically javadocs will be referred directly from internet.
Complete steps:
Open the Build Path page of the project (right click, properties,
Java build path).
Open the Libraries tab.
Expand the node of the library in question (JavaFX).
Select JavaDoc location and click edit.
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
Neither Project/Properties/Javadoc Location nor Project/Properties/Java Build Path/Libraries had not helped me until I picked and moved up in "Order and Export" tab of "Java Build Path" "Android Dependencies" and added-in-library.jar. I hope it will be useful.
Alternatively you can also,
1) Navigate to that method by Ctrl+Click on the method. The new tab/window will opened with text "Source not found" and button "Attach Source.." in it
2) Click the button "Attach Source.."
3) New window pops up. Click the button "External Folder"
4) Locate the JavaFX javadoc folder. If you are on Windows with default installation settings, then the folder path is C:\Program Files\Oracle\JavaFX 2.0 SDK\docs
First, if you get the message
Note: This element neither has attached source nor attached Javadoc and hence no Javadoc could be found
Then it means that you've already included the external jar needed for your project.
The next step would be to associate the external jar with its javadoc url.
go to package explorer, expand your project folder, expand referenced libraries
right click the external jar that you want to associate its javadoc with
click properties -> javadoc location
copy and past the url for the javadoc that you googled online into the javadoc location path
click apply
And you're all set!
Above all answers are right but there is another method also which is very handy.
Pre-condition: Your project is Maven project Or converts it to Maven project.
RightclickOnProject > Configuration > Convert in to Maven Project
- Now follow the steps:
1. Select any jar for which you want to download sources or javadocs.
2. RightClick > Maven > Download javadoc or Download javasources
I couldn't get the "Attach source..." method to work either, and I tried many different ways. The Javadocs for JavaFX are installed in Program Files\Oracle\JavaFX 2.x SDK\docs. Another way to install the Javadocs is:
Right click on the project, select Properties
Select Libraries on the right side of the tab
At the right top side of the tab, you may see "Default JavaFX Platform" or something similar. Click on the Manage Platforms button. (You can also install this default platform from here if you haven't got this already).
In the Java Platform Manager tab which appears, select "Default JavaFX Platform" on the left side, and then click on the JavaFX tab on the right side of the window.
One of the entry fields is labeled "JavaFX Javadoc". Click the "Browse" button next to this field and browse to the installed docs file mentioned above.
Hope this helps some people who were as puzzled as I was.
In addition to the answer of #dhroove
(would have written a comment if I had 50 rep...)
The link has changed to:
http://docs.oracle.com/javafx/2/api/
At least my eclipse wasn't able to use the link from him.
It already in a different thread, just a simple eclipse setting will automatically download JavaDoc (but, you need to click the method for first time).
Where can I download the JavaDoc for JPA 2.0?
This trick worked for me in Eclipse Luna (4.4.2): For a jar file I am using (htsjdk), I packed the source in a separate jar file (named htsjdk-2.0.1-src.jar; I could do this since htsjdk is open source) and stored it in the lib-src folder of my project. In my own Java source I selected an element I was using from the jar and hit F3 (Open declaration). Eclipse opened the class file and showed the button "Attach source". I clicked the button and pointed to the src jar file I had just put into the lib-src folder. Now I get the Javadoc when hovering over anything I’m using from the jar.
If you are using maven just do:
mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true
You could specify the online Javadoc location for a particular JAR in Eclipse. This saved my day when I wasn't able to find any downloadable Javadocs for Kafka.
In the Package Explorer, right click on the intended JAR (under the project's Referenced Libraries or Maven Dependences or anything as such) and click on Properties.
Click on Javadoc Location.
In the Javadoc location path field under Javadoc URL, enter the URL of the online Javadocs, which most likely ends with /<version>/javadoc/. For example, Kafka 2.3.0's Javadocs are located at http://www.apache.org/dist/kafka/2.3.0/javadoc/ (you might want to change https to http in your URL, as it raised an invalid location warning after clicking on Validate... for me).
To attach the Java source code with Eclipse,
When you install the JDK, you must have selected the option to install the Java source files too. This will copy the src.zip file in the installation directory.
In Eclipse, go to Window -> Preferences -> Java -> Installed JREs -> Add and choose the JDK you have in your system.
Eclipse will now list the JARs found in the dialog box. There, select the rt.jar and choose Source Attachment. By default, this will be pointing to the correct src.zip. If not, choose the src.zip file which you have in your java installation directory.
java source attach in eclipse
Similarly, if you have the javadoc downloaded in your machine, you can configure that too in this dialog box.

Categories

Resources