Ordering and Sorting Libraries in Java Eclipse - eclipse

In Eclipse, on many occasions i have had issues with the order in which libraries and jars of a project are loaded. i.e. Project -> BuildPath -> Configure Build Path -> Order and Export.
I have the following questions:
Are libraries loaded with preference?
If two libraries conflict, which one overrides the other?
Should the src folder be at the top or should it be the JRE System Library. If so, Why? Is this trivial?
Direct answers or references to reading material would be great.

A quick google and I found a good reference about this "Order and Export" tab, from here on stackoverflow.
The "Order and Export" tab in "Java Build Path"

A quick look into that in eclipse and I found that eclipse is only allowing a reordering at library group level, not at library level, as the question was.

Related

Easy way to find which Eclipse version and plugins are needed for existing Eclipse project

I was given a working Eclipse project in Java. If I open it in some version of Eclipse then I get numerous errors. I get them because my version of Eclipse differs (it is not web developer) and vaadin and ivy plugins were used to create the project. How can I understand which version of Eclipse and which plugins are needed? I can get some sense by looking in .setting folder. There are a lot of files with names as namespaces related to plugins. Is there more direct or automatic/semi automatic way to find which plugins and Eclipse version are needed?
No. The Eclipse developers expect you to know your tools and if you take over a project from someone else or join a project, that someone explains to you how to install and configure Eclipse.
To find out which Eclipse plugins you need, look into the file .project and the folder .settings. Google for the file names and plugin IDs to see what they might mean. Usually, the third word of the name is the project (org.eclipse.jdt.* -> JDT project).
For missing classes, you need to look at the classpath. The easiest way to do that is to right-click on your project name and then select "Properties" from the menu. There is an entry "Build Path" which contains all the dependencies. Click through the tabs to see what you need.
For plugin projects, look into the file META-INF/MANIFEST.MF; Eclipse should open a special editor when you open it which has a tab for dependencies.

F3 on Eclipse doesn't go to the class that was selected

Background
I have multiple android libraries, each has its own classes.
The problem
For some reason, for classes that extend from one of those libraries' classes, when I click F3 to go to the class itself, I get an error:
"The Jar of this class file belongs to container 'Android Dependencies' which does not allow modifications to source attachments on its entries"
What i've tried
I've done some searching of this issue, and found multiple solutions (for example here, here and here), but none has worked for me:
clean project
set the order of the build path to have src at the end, while gen folder is before it.
update ADT, as it was probably fixed.
add "Source attachment", but this is impossible for android libraries (blocked for some reason).
The question
Why does it occur?
How come it's still occuring even on the newest ADT ( i have 22.3.0.v201310242005-887826 )?
Quoting from mik3y In Eclipse, how can I quickly access the source of an "android library project" from the source of a project that uses it?, which worked for me:
Right click on the non-library project (Project B) and select Build Path:
In the Projects tab, add the library project Project A as a dependency.
In the Order and Exports tab, be sure Project A is given higher precedence than the placeholder/bundle Library Projects.
I had to do both of these steps in order to fix this issue, with ADT15, Eclipse 3.7 and new projects.
EDIT:

Equivalent of "Order and export" of Eclipse in Netbeans

I'm using Netbeans 7.2.1 in Ubuntu 12.10 and I'm trying to change the order of class loading. I have two classes in same package with the same name, but one is in my sources and the other one is in a JAR. The class in my project sources has a higher priority and I want to use it instead of the class in the JAR. In Eclipse I can change the order under the "Order and export" tab in Project Properties -> Java Build Path.
Netbeans seems to priorize JAR classes higher than project sources by default. How do I change the class loading order?
Note: I discovered the answer while I was writing the question and I hope it will be helpful for someone with a similar problem.
Go to Project Properties -> Libraries -> Run and make sure that "Compiled Sources" is above "Classpath for Compiling Sources" by selecting it in the list and clicking "Move Up".

How can I get Eclipse to index an entire C/C++ source tree that contains multiple "make projects"?

I'm having trouble getting Eclipse to index my source code. I'm using Eclipse Helios on Windows XP at the moment.
I have a directory called src. Within it, I have a bunch of dirs, something like this:
src
-include (common headers)
-lib
-libIO (source code for this library)
-libGUI (source code for this library)
-pgms
-pgm1 (source code and headers for this pgm)
-pgm2 (source code and headers for this pgm)
Each leaf has its own Makefile. There is no top-level Makefile in src. pgm1 can and does include files from include and lib/libIO and lib/libGUI.
Basically, I want Eclipse to index my entire src directory, without having to set up a C/C++ project for every leaf in my tree. I can't seem to find a way to make this happen.
Here's my symptoms; what I'm trying to solve for:
When editing source in the pgm1 dir, it references functions that are declared in my include dir header files and defined in source files found in lib/libIO.
However, when I press F3 to get to the declaration of a function, Eclipse says "Could not find symbol 'X' in index". I can't seem to get Eclipse to find either the header declaration or the source definition for the method under my cursor (like the Java module does perfectly). Is this possible?
I had exactly same issue as OP but for some reason the menus in Eclipse I was using (Helios Service Release 2) were not "Go to Properties -> C/C++ General -> Paths and Symbols -> Source Location.".
The way I fixed the issue was :
in C/C++ view, right-click on top project name;
in the menu, select New->C++ Project;
in the window that appears, select Convert to and then select C++ project;
click OK to close the window.
Eclipse will start indexing right away. Depending on the size of source tree it may take a while but you will have the indexing working finally after that.
I faced similar situation. I solved it in this way: right-click the project in project View-->select Index-->rebuild.
I managed to solve this thanks to comments here.... I ended up recreating my project. I used the Import method to download a project from CVS, and told it to use the New Project wizard to do so. When I got the New Project dialog, I told it this was a C++ Project, and the indexing now works fine.
I still wish I could index files without having to attach a specific project type to it, but at least I found an answer.
Thanks for the help all.
Exit Eclipse. In workspace go to ".metadata/.plugins/org.eclipse.cdt.core" and delete everything in there.
in the project explorer panel, right click the project you want to re-index, then select index, then select the action you want
Indexing of files and variables under different flags is always complicated when we have a huge project, lot of files and more importantly lot of different build options. I prefer playing around with the Indexer option to help me browse the entire code.
You can find it : Project Properties>C/C++ General/Indexer.
You can choose "Enable project specific settings"
Then it's up to you to choose the options you want for your project.
For a particular build we can choose "Use active build configuration" so that only the files and MACROS are considered which are used by the build script.
Or Index all source files in the entire project.
I am using Eclipse Neon 3, here's the solution that worked for me :
go to File
New
Convert to C/C++ Autotools project
then select your project and finish.
It can take some time to finish indexing, it depends on your project size.
I have experienced problems with the indexer of Eclipse Luna when there was an unresolved friend declaration in the class declaration - it seems then that the indexer skipped indexing the rest of that class, and all references to it was shown as unresolved by the indexer.
Solution: removed the unresolved friend declaration (in my case, it was legacy code that was no longer needed).
Please try the following (my project is set up differently, so I am not sure this will work for you).
Go to Properties -> C/C++ General -> Paths and Symbols -> Source Location.
Do you see your source folder there?
I observe this behavior:
When I add a source folder and then exclude it from build, it disappears from the above list. After that the folder is no longer indexed. Re-adding it to "Source Location" solves the problem: the folder is now indexed; remains excluded from build (as intended); is visible among source locations.
I believe it is a bug -- excluding a source folder from build should not remove it from source locations list.
In Coocox IDE (Eclipse + gcc) the problem is resolved by going from file menu
Edit > Preferences > C/C++ / Indexer > Build configuration for Indexer set to Active build configuration and the rebuild the project (Ctrl R).
If the project is already converted to C/C++ and still the index is not working you can right click on the project and Index and rebuild. The project will start indexing right away.
I am using
Eclipse IDE for C/C++ Linux Developers
Version: Helios Service Release 2
Build id: 20110218-0911
I followed the suggestions above and in addition I had to mark all referenced projects (with in the work space) using project properties->Project references
The following has worked for me in Eclipse Neon:
New Project -> C/C++ -> Makefile project with existing code -> Next. Then Navigate to the code and finish the project creation. Indexing starts automatically.

What happened to the "Enable Nested Modules" option in m2-eclipse?

I contribute to and implement some open source projects that use a Maven2 build system organized into several sub-modules. I've also been an Eclipse user for several years. With these projects, I have historically leveraged the maven-eclipse plugin so that Eclipse can correctly recognise library dependencies in my project.
It used to be the case that -- when I set up a new workspace or project -- I would have to right-click select "Enable Dependency Management" followed by right-click "Enable Nested Modules." Once I did these things, maven & eclipse would find dependent libraries properly in my .m2 local repo.
But in my most recent install of Eclipse/m2-eclipse -- Eclipse Build 20100218-1602, m2-eclipse 0.10.0.20100209-0800 (sorry, the "About" dialog doesn't provide anything better than that) -- the "Enable Nested Modules" option is missing. Nor does the project seem willing to find my nested modules without it.
After much digging and some trial & error, I got the IDE to recognize my sub-modules by setting...
includeModules=true
In my org.maven.ide.eclipse.pref file manually.
But my question is: what gives? Why did this option disappear? Is there some newer, better way that I should be using m2-eclipse to find nested modules? How are other Maven & Eclipse users dealing with this issue?
The thing here is the option to enable nested modules was moved to the Window >Preferences > Maven. Set the Support multiple Maven modules mapped to single Eclipse Workspace project checkbox, right click your project, navigate to Maven menu item you can find the 'Enable nested modules' option.
Looks like support for this feature was recently removed:
https://issues.sonatype.org/browse/MNGECLIPSE-2291
Why did this option disappear? Is there some newer, better way that I should be using m2-eclipse to find nested modules?
Could this be somehow related to the option below (accessible via Windows > Preferences > Maven):
To be honest, I'm not 100% sure because I don't create my projects under Eclipse, I create them on the command line outside Eclipse and import them as Existing Maven Projects (and this works with nested modules).