Eclipse maven externalToolBuilder - eclipse

I have a maven project, and i'm surprised that .project and .externalToolsBuilder are under svn.
Someone explain to me that its because we need to create a builder automaticaly when developer's import project under eclipse.
Does it possible to add in pom.xml all that i need to create this builder when project is imported into eclipse wihout need to commit .project file?
Because i want to have a clean directory without .project/.classpath etc... before import my project and i don't want this file under svn
thanks a lot.

The answer to your question is clearly "yes". It is possible to set up Eclipse from a pom.xml file and have Eclipse generate the files it needs from there.

Yes, you can generate the .project file, but not the files in the .externalToolBuilders folder. And if you have custom builders those should be added with <additionalBuildcommands>. See eclipse maven plugin.
So, the .project file shouldn't sit in svn, .externalToolBuilders. You can generate those too, as you can see in the eclipse maven plugin, but the content still has to be somewhere (your pom, a server etc).

Related

How to connect Maven and Perforce in eclipse?

I am new to maven but have used perforce for quite sometime.
Our project repository is on perforce. Basically there's multiple folders with their own pom files.
What I'm doing currently is, on the command line I create a perforce workspace and sync the latest depot version. Then in eclipse, I go and import a maven project and give the path to this folder that i synced on the command line. Now i don't mind doing that, but whenever I edit a file, I have to manually go to the command line for that file, find it and do a p4 edit on it which is very annoying.
Is there a way to have my project imported as Maven and it automatically sync with my Perforce depot within eclipse. I have already tried using the p4 plugin but it checks out the depot as it is and does not give a project level view and I can't do a maven build/maven install on it.
I have also tried to import maven project from scm, but looks like maven doesnt support perforce within eclipse?
Please help, i'm struggling a lot with this.
Thanks.
You can do that by installing Maven and Maven scm plugins.
You also need to have perforce and perforce connectors add in installed.
And then by importing the project.
Check for more details here
Checkout Maven project from SCM - no connectors
https://books.sonatype.com/m2eclipse-book/reference/creating-sect-importing-projects.html
Best Regards,
Saurav

pom.xml greyed out when importing maven project into eclipse

In eclipse Mars, I could always clone a git repository and then import it as a maven project. But this time, the pom.xml is greyed out. On the next screen only the pom of another project is showing and I can't proceed.
Are you sure you have not already imported the project into the workspace? Maybe you just don't see it. One reason can be that you are using working sets and the project is not in the group you'd expect it to be in?
If the project is already imported into your workspace, and you are trying to import another copy of the same project that resides in a different folder, you can try adding some string for Name Template under Advanced and the importing.

self-describing project in Eclipse using m2e

I'm using Eclipse and m2e to import a Maven project into Eclipse.
The eclipse documentation states the following about the .project file:
The purpose of this file is to make the project self-describing,
so that a project that is zipped up or released to a server can be
correctly recreated in another workspace.
However, the .project file does not contain no information about the imported Java files nor the pom.xml. It only contains some build commands and natures. Thus, I don't understand how it makes the project self-describing.
It seems that each developer that downloads repository for the first time will need to import the Maven project inside Eclipse again. I'd like to have a meta file that contained at least the pom.xml path so that developers could have a ready environment after downloading the repository content and didn't need to import the Maven project into Eclipse. Is that possible?
Technically speaking, Eclipse doesn't know anything about maven. The .project file is Eclipse's way of storing metadata about the project in a file that's contained within the project (although nowadays some of that metadata has moved to the manifest.MF file). The .project file still contains information about natures (which are used by tools to identify which projects are of interest to the tools) and builders (which describe what tools to invoke as resources in the project are changed). In this way the .project makes the project self describing.
Maven is a relative newcomer (albeit a stable and well-established one) to the Eclipse world. As you point out maven stores all of its project info in a pom.xml file. Maven fits itself into the Eclipse world by providing two actions, "Update Project Configuration" and "Update Project Dependencies", that take the information in the pom.xml file and update the contents of the .project and .classpath files.
So instead of manually editing the .project and .classpath files as you suggest, a developer only has to invoke those two functions after extracting an Eclipse project from a repository.

new maven POM file in eclipse java project

Have upgraded to eclipse.indigo using a new installation. Added m2e. Maven shows up under Windows>Preferences. File>New>Other>Maven gets the following options: Checkout ..., Maven Module, Maven Project. The Maven POM file option is missing. I'm trying to add Maven support to an existing Java project. Have read the manuals, searches, helps, etc. No explanation as to why the Add POM option is missing. Any idea how to get this option to appear?
In order to create a POM on your project, and also change the project structure to Maven default, right-click on your project > Configure > Convert to Maven Project.
Don't forget to choose the correct Packaging type (in your case I guess it will be POM).
I don't have this option either, seems to have disappeared with the latest version. This bug report seems to point in this direction as well:
https://issues.sonatype.org/browse/MNGECLIPSE-2709
The standard way should be to create a new Maven project through the wizard, which will then also contain a POM file. You could use that to create a dummy project and then copy over the POM file.
In most cases, I also just copy an existing POM file to the project and start with that.
Quick workaround: Adding a POM by hand. (Also I'm not sure that I've ever seen an "Add POM" option.)
Simply add a file to your project (New > General > File), and name it pom.xml. On double-click on this file, the POM Editor will open.

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)