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.
Related
I have been desperately trying to import a multimodule maven project from GIT into my (freshly installed) STS 3.9.4.
During the last hours I tried lots of solutions that were posted on stack overflow, but none of them worked for me.
These are the steps I did:
git cloned the repo from the command line (intentionally, because it didn't work either when I used the GIT integration of STS)
imported the project via File / Import / Maven / Existing Maven Projects
After the project was imported, it looks like this:
(please ignore the red icon at the top left, the problems persists even when this icon is not there)
I can Run As / Maven Install any pom.xml, but when I try to edit java sourcecode Eclipse tells me The resource is not on the build path of a Java project.
To fix this I tried:
convert to faceted form
added Java nature
Configure Build Path / Set as source folder
add buildcommand org.eclipse.jdt.core.javabuilder to .project
Being able to build is fine, but editing sourcecode without support for Organize Imports, Format Source, and so on is a real pain.
From your screenshot I assume the modules are nested within the directory of the reactor pom(=parent pom) and you have imported all of them as projects (reactor and modules).
Don't add a java builder to the "reactor" project.
Make sure not to open the java files from the projects corresponding to the reactor pom, but from src folder within the corresponding module projects.
The solution to this problem was somehow hidden, but in the end I have to say the reason was clear.
After I checked with a different multimodule project (https://github.com/Activiti/Activiti.git), I was sure that my STS and other components don't suffer from a generic problem. So the cause must be located in the project itself.
The multimodule project was setup correctly on the pom.xml level. But the topmost pom.xml was modified: most of the modules had been commented out:
The developer who introduced that change didn't experience any problems because he kept his already existing workspace. And the problem only occurs when a new workspace gets created and maven scans the pom files.
I want to import it to eclipse as a maven project .i want to know it from very first step? any sources?
The first step is to import your GitLab "project" (meaning a repo cloned from a GitLab server) into your Eclipse workspace.
If it is a java project, then you can use a plugin like "eclipse-to-maven" to convert that project to maven:
Converts .classpath files into pom.xml
If required, prints the dependency graph of eclipse projects.
Moves source folders according to Maven convention. So for instance Java sources go to src/main/java folder.
Removes spaces in the names of the folders. So "Calculator Component" becomes "CalculatorComponent"
Other manual conversions are described in "Convert Existing Eclipse Project to Maven Project".
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).
I have a maven project that uses other small projects. And I added them to master's pom file.
So my Eclipse project properties looks like following:
>Master project
>Java Resources
>Libraries
>JRE System Library
>Maven dependencies
>smallProj1.jar
>smallProj2.jar
The thing is I do not have the all code for smallProj1 and smallProj2 and whenever add them to my workspace Eclipse overrides the maven dependencies and simply calls the two projects instead the jar files from my local maven repository and then I have all over the code those red underlines. Project properties in Eclipse looks as following after I add them to my workspace:
>Master project
>smallProj1
>smallProj2
>Java Resources
>Libraries
>JRE System Library
>Maven dependencies
>smallProj1 (not jar anymore - folder)
>smallProj2 (not jar anymore - folder)
Since I also want to have a look to smallProj1 and smallProj2 code while I am coding, I want to keep them both in my workspace. But I want my Master project to use the jar files that I provided, not the small projects in the workspace.
Any ideas on that?
You could right click on a project and set "Maven" -> "Disable Workspace Resolution". This will let Maven find the dependencies from Maven and not within the workspace. I don't think it is possible to do this on a dependency basis.
But I think in your case it would be better to fix the broken smallProjX in your workspace (as they exactly contain the code you need), so that the master project could be build correctly.
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.