When I run an application into eclipse, if an exception is thrown and is showed in the console, then you are able to click on the links which takes you to the source code file.
Fine, the problem is that when I click those links they open as external uneditable resources (different icon in the editor tab, Java source files have a blue J but these files have the J empty, only showing the border). Same problem when debugging, the files opened are not the same tabs as the ones edited.
For more information, while the normal source files shows in the title bar something like:
project/path/to/source/file.java
The others show its complete path:
C:\absolut\path\to\source\file.java
This is quite annoying since I have to go and back from one to the other and I have no idea where to change this or why it is happening (it was alright a time ago).
Any hints on how to edit this?
Thanks
It is a classpath problem. When you click, you are actually accessing the file from the classpath.
To view the Java file, you have to add a reference to your project in the classpath and move it to the top of the classpath list.
You can also try converting it to project facets java version, right click on project --> properties --> choose Project Facets -->java 1.7 or [your version]. Apply.
Related
I have a problem with my war.xml file in that it isn't picking up my class files correctly for spring.
The line that is wrong is:
<dir sourceOnDisk="C:\myApp\src\main\java" targetInArchive="/WEB-INF/classes"/>
I need:
<dir sourceOnDisk="C:\myApp\bin" targetInArchive="/WEB-INF/classes"/>
Now, I can change the file manually (from src\main\java to bin), and it works correctly for a while, but every now and again something decides my war.xml file needs to be rebuilt, and things then break again.
I added my application by dragging my project from eclipse's Project Explorer tab to my liberty profile server instance within eclipse's Servers tab.
Where is the menu option within eclipse to change this?
To automatically map your bin folder to the WEB-INF/classes folder, select your project on the Project Explorer, right click it and select Java Build Path. In this property page on the Source tab, you can add, edit or remove the source folder, and also modify the default output folder. In this case you may only need to modify the output folder, to something similar to (project-name)/bin
Regarding the *war.xml file located at (server-dir)/apps, this will be refreshed each time you modify your project in eclipse, if when doing it, you have your server started and with automatic publish enabled. Usually you don't modify this file yourself, but you can read more about it here: http://www-01.ibm.com/support/knowledgecenter/SSAW57_8.5.5/com.ibm.websphere.wlp.nd.doc/ae/rwlp_loose_applications.html?cp=SSAW57_8.5.5%2F1-14-1-10
Turns out the correct place to change things is in the Deployment Assembly option when you right click on your project...
In JBoss (Eclipse) I am having a problem with my src files showing up in the src folder in the package explorer. As you can see from the picture on the left there is nothing in the folder for test, and no java files under main, but webapp. For example though I went to where the files are stored and show you that there are infact tons of files inside of the test folder. Any idea how to get them to show back up in the Package explorer in eclipse?
edit: srry forgot pic
In Eclipse, make sure the filter is not turned on to hide types of files you're looking for. Under Package Explorer, click the small down arrow to the top right of your listed projects. In that list, select Filters... then make sure you're not filtering out the files you're looking for. Checked items are hidden from your view.
Otherwise, the picture you've said you posted, I can't see. So I'm sort of guessing what the problem really is here.
EDIT: OK, I see the picture now.
Java files are shown under src/main/java at the top of the package explorer. If you right-click the project name, select Build Path -> Configure Build Path... and select the Source tab, you can see which folders have been designated as containing java source files.
Files in those folders will have been filtered out from the main "plain" type folders. Eclipse treats stuff marked in "source" folders differently. Mainly, it will attempt to compile java files it finds there.
Solved it, It was just that I was in regular Java perspective instead of the JBoss perspective. Honest silly mistake. Thanks for the replies though!
I'm attempting to run an already existing eclipse project created by another person.
After importing it to eclipse, and attempting to Run As->Java Application, it fails because it cannot find a .properties file in bin/resources
I printed out the classpath eclipse was using
logger.info(System.getProperty("java.class.path"));
and sure enough, it includes bin, and all the lib/*.jars, but not bin/resources. Copying the .properties file into bin makes the program work, but I wanted to understand how to add a directory to the eclipse classpath.
I tried several things, none of which worked
export CLASSPATH=$CLASSPATH:/home/me/programdir/bin/resources
This didn't work. I understand it's not a desirable way to approach the issue, but I had thought it would fix the problem (I have more of a windows than linux background so perhaps I am missing some nuances of system variables in linux)
Next up, I tried modifying the VM arguments in the Run->Configurations dialog in Eclipse
-classpath "/home/me/programdir/bin/resources"
No luck here either, which confused me, as I was sure it would work and seemed like a reasonable solution to a specific program needing one additional folder added to the classpath.
Next I tried modifying build.xml directly. I found the part that defines the classpath and added my own line for bin/resources, as follows:
<path id="classpath">
<fileset dir="./bin/resources" includes="**/*.properties"/>
<fileset dir="./lib" includes="**/*.jar" />
</path>
this too was unsuccessful. This perplexed me even more, so I commented out the entire path element, and the classpath printed out by the logger was unchanged, so it is apparent that whatever classpath eclipse was using, it certainly wasn't this one. This seemed to me the best solution, had it worked: the build.xml file could be checked in with the correct additions to prevent future users from experiencing the problem.
Next I tried the IDE approach. Run->Configurations->Classpath-> User Entries->Advanced and simply added the bin/resources folder. That worked perfectly, the program finds the properties file, all is well. However, I am dissatisfied that my previous efforts failed without me really understanding why. It seems that each one should have worked.
Additionally, I want to ensure that I fix this problem in such a way that it is captured by the code I check in so that subsequent users do not have to go through the same steps. My solution is thus not very satisfactory as I am not sure what actual piece of code changed, and thus cannot verify that the 'fix' is checked in.
How do you find the actual definition that eclipse is using for its classpath? I had thought it would be the build.xml classpath definition, but that did not seem to be the case at all.
In Eclipse, there is a build classpath and a runtime classpath. There is also the build output location, which by default is bin. You don't want to add resources directly to bin because Eclipse can delete its contents when doing a clean build. What you need to do is add a resources folder in your project to contain any non-Java files that you want included in your build output.
To include the contents of this resources folder in the build output (bin), right-click the project and select Properties. In the Project Properties, select the Java Build Path section, then the Source tab.
Use the Add Folder... button to select the resources folder from your project, then OK to save the changes. At that point, Eclipse will automatically copy everything from resources into bin when it builds.
This is for a maven project:
Right click on project
click on run configurations
click on the classpath tab (Oxygen Eclipse)
click on user entries
click on Advanced
first radio selection default should be 'Add Folders'
click OK
Follow these steps to get this issue fixed:
Right click on Project
Click on Run As and select Run Configurations
Click on the classpath tab (Oxygen Eclipse)
Click on user entries
Click on Add External JARs.. and choose the downloaded JAR file
Click Apply and run your project...
Right Click on the project-name in Package Explorer, select Properties, select Java Build Path on the left, select Source tab on the right, click on Add Folder, browse through the project's directories to select the resources folder or whatever you need to add to the eclipse classpath, hit OK, again hit OK. Done.
If you don't want the properties file to be copied to the bin folder, you can try the following:
Right click your project, select Build Path, select Configure Build Path..
Select Libraries tab
Select Add class folder..
Add your resource folder.
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)
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.