How do I prevent Eclipse from indexing things in Maven repo JAR files? - eclipse

I’m using Eclipse Kepler on Mac 10.9.5, the M2Eclipse plugin and Maven 3.2.3. I would like to prevent Eclipse from indexing JAR files, in particular things referenced in my M2_REPO directory. Within Eclipse, I click Shift+Command+t, type “OrderServiceImpl” (A name of class in the project), and saw
OrderServiceImpl - org.mainco.subco.myproject.service - orders/src/main/java
OrderServiceImpl - org.mainco.subco.myproject.service - M2_REPO/org/mainco/subco/orders/79.0.0-SNAPSHOT/orders-79.0.0-SNAPSHOT.jar - /Users/davea/.m2/repository/org/mainco/subco/orders/79.0.0-SNAPSHOT/orders-79.0.0-SNAPSHOT.jar
Is there a way I can prevent Eclipse from indexing things in JAR files? I would like to exclude all of them but if that’s not possible, at least things included in my M2_REPO directory (dependencies brought in through my pom.xml file).

Regardless of what Eclipse indexes, you can specify filters on what the "Open Type" window shows using Working Sets:

Related

Mark Occurrences for binary files in STS

I have created a project using maven in Spring STS. I opened a source file(class file which is downloaded by maven automatically) and placed cursor on methods/variables those occurrences not highlighted in class. How can I fix that?
This is complicated and it is not a maven or an STS bug. Rather, it is a Eclipse JDT bug. Mark occurrences cannot work unless the class file and all of its dependencies can be classloaded using the current project's classpath. So, there must be some dependency that is missing for the class in question. It is probably available at runtime through maven, but just not at edit time.
It is very tricky to fix this problem, but you can start by explicitly adding all transitive dependencies to your pom.xml.

How to get peer project source in eclipse and maven

creating a parent project with only a pom.xml, and lots of sub projects such as:
my-web
my-core
my-backoffice
etc. is easy, and the sonotype eclipse plugin does most of the work.
However, getting one project to know about the source in the other project seems to be hard. E.g. when you are debugging the my-web project, and step into my-core, eclipse doesnt know where to get the source.
Looking in the Java Build Path in eclipse, the maven plugin has added my-core as a folder under "Web App Libraries". I.e. its not using the my-core-0.0.1.SNAPSHOT.jar or similar, its using the raw java files. Great!
But how to tell maven to tell eclipse to look for the source in the same place?
Im not really sure where to start. Im guessing its possible to get maven to put the source in a special jar using the maven-soure-plugin, but this will usually be out of sync with the actual java files which the web project seems to be using directly.
A quick and dirty solution is to manually Edit the Java Build Path for each project, and add my-core and other dependant projects in the "Projects" tab. Is this best practice? Any other suggestions?
A quick and dirty solution is to
manually Edit the Java Build Path for
each project, and add my-core and
other dependant projects in the
"Projects" tab.
If this doesn't happen automatically you have a configuration problem.
My Guess would be that you have a version mismatch between the pom dependencies and the actual project versions. Or your projects have an unusual name template (m2eclipse resolves projects by their artifactId AFAIK)
Either way, what always helps is in your Debug configuration (Run > Debug Configurations ...) select the Source tab and just Add... the selected projects.

Maven project is in a subfolder, can't get Eclipse integration to work

Inside the folder 'ProjectName' exists several subfolders, and of them contains java program:
ProjectName
Specifications
JavaCode
Gfx
...
JavaCode folder contains pom.xml.
I have installed m2eclipse (0.10.x) to Eclipse and imported whole ProjectName folder to Eclipse. Subfolders are displayed correctly but maven integration is not working correctly - for example I don't see src/main/java "shortcut" folder in Eclipse, but I have to click to open all folders.
If I create a new maven project with Eclipse from scratch, the integration works well.
What could be the issue?
Select the JavaCode folder and then invoke File... / Import... / Maven Project. That would bring your Java code into Eclipse as a proper project with Maven support enabled. It is fine to import several overlapping folders. So, you could use the parent for version control purposes and JavaCode would be the actual Java project you'd work with in the IDE.
Unfortunately there is no way around that, unless you want to move your pom.xml to the root project and remap all the Maven plugins to folders under JavaCode project. But that would be really bad idea and Maven integration for Eclipse may not work with such project structure without an additional tweaking.

Changing Eclipse project to use Maven?

My boss asked me to convert one of our projects to use Maven to build. So I created a pom.xml file and now Maven builds the project fine and runs all the tests and everything. "Fine", my boss said, "We don't need these any more" and he deleted the /libs directory from the project, and he deleted the JRE from the classpath. That's fine, it still builds in Maven, but Eclipse shows everything that was in the jre or in /libs as unresolved in the editor. Because of all the error indications, I'm seriously considering going back to vi. How can I get it so Eclipse can do its thing?
To create the Eclipse .classpath and .project files, do the following:
mvn eclipse:eclipse
This will create references to your local Maven repository, which means that you'll have to build at least once with Maven, so that it can download the files. I believe you also have to define an Eclipse classpath variable M2_REPO (at least, I have one defined, and can't see any other reason I'd have done that).
I'll assume your boss deleted the JRE entry from the Eclipse classpath, which was dumb but not as dumb as deleting your actual JRE directory. The Maven-build classpath file should include something appropriate, or you can go into the "Build Path" dialog and add the JRE via the "Libraries" tab.
Oh never mind - I clicked the "Maven->Enable dependency management" and that fixed it. Don't know why I didn't think of it before.
Use a Maven-Eclipse plugin.
http://mevenide.codehaus.org/
http://m2eclipse.sonatype.org/
You can use plugins as Nick mentions, but you can also solve this very simply by pointing eclipse to your local maven repository.
1) create a classpath variable, M2_REPO, in your workspace. It should point to something like "c:\Document and Settings\yourname.m2repo\
2) Add the jars that you need.
These steps can also be automated with mvn eclipse:eclipse goal as well. The docs are here, I used it in the past but had some difficulties customizing it (for WTP and Spring configuration files under /.settings/ folder in the project)

Eclipse treating all the files in a project as Derived

I have created a Dynamic Web Project in my Eclipse workspace. It is also a Maven project, and under SVN control. But in "Open Resource" (Ctrl+Alt+R) no file from this project appears, unless I check from the window's options (top right drop-down) "Show Derived Resources".
I have checked on some of the project's folders and they are not marked as "Derived".
I have two more (plain Java) projects in the workspace, and all the files from them are visible in "Open Resource".
Do you know what might be wrong with either Eclipse, the Maven plugin or Subclipse (the SVN plugin)?
I experienced a similar issue in Eclipse (Ganymede), when using the Maven and Subclipse plugins. I have not determined which plugin caused this problem, but I suspect that it is related to my pom.xml containing nested modules (ie. a <modules><module>main-module</module><module>integration-test</module>). These appear in Eclipse as nested folders with their own pom.xml files (I did not use the Multiple Projects plugin although I have installed it).
I assume that one of the plug-ins has incorrectly set the derived flag on these folders when I checked out the project by SVN and then updated the MVN dependencies and project settings.
When I right click->properties on the top-level nested module directories I can see the Derived flag is checked. By unchecking the derive flag on the module directories (and checking the derive flag on the target directories within each sub-module instead), it fixed the Open Resource functionality.
As the derived flag is inherited from directories, you may need to check all of your directories in the hierarchy to find the 'culprit'.
If it helps the plug-in authors, my top level module directories contain a hyphen '-' in their names. Maybe that is throwing out one of the plugins.
I think it is the maven plugin:
Jira issue
See also the notes for July 31, 2008 at the New and Noteworthy page for m2eclipse.
Several other nice links deleted because of restrictions of stackoverflow.
In fact, I think that somehow this is eclipse in its own right, as I don't have m2eclipse or using maven for this.
By default, eclipse uses /bin as the target directory. My situation is similar to having maven in the project in that the target directory was changed to lib/classes to accommodate an existing project.
I started seeing issues similar to what is reported here, and while searching for the problem, came across this solution. Eclipse somehow didn't "uncheck" the bin directory as no longer derived, so I ran into the same issues. I tried replicating it, but I couldn't.