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

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.

Related

Importing multimodule maven project from Git into Eclipse/STS

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.

are there different ways of importing git repository to Eclipse?

Why when I import a git project it does not appear like full package path view (main.java.comformance) like this image:
I have imported this project before but now in the package view, it only appears as a tree of folders and not full package path view like main.java.comformance with package icons. I wonder what I'm doing differently now. I followed the instructions in this video: https://www.youtube.com/watch?v=L8IeaWHZCRo)?
Both projects on the screenshot do not seem to be configured correctly (probably because they were not created with Eclipse or files like .project were not shared):
The project on the right side is obviously a Maven project (with probably this pom.xml file): the Java source folder should be src/main/java/ (default of Maven) instead of src (default of Eclipse) and the Java packages for instance uk.ac.manchester.cs.jfact instead of main.java.uk.ac.manchester.cs.jfact.
The project on the left side is not even configured as a Java project.
The simplest way is to use the Eclipse Smart Import feature (instead of configure everything manually): the Java nature of the project will be detected even without the .project file and also the pom.xml file is read to get the required JARs and to configure the Java build path and source folder(s) automatically:
Clone the Git repository
In the Git Repositories view right-click the Working Tree node and choose Import Projects...
Do you see the "J" in the icon next to the project name "jfact" at the right image?
That means that it is a "java" project. Eclipse does not know anything about your project.
You will have to do one of this:
Checkout the project again with Eclipse and use a "wizard" configuring it as a java project.
Enable Project Facets (right-click on the project name), and then enable "Java" in the Project Properties/Facets. This is not trivial, so I don't recommend this. - If this is a solution, actually I don't know for sure -
If you are using maven, close the project and execute mvn eclipse:eclipse to convert/create the project files for eclipse, and open again the project.
After you manage it to become a Java project, furter steps could be needed, but maybe will be enough.

Eclipse adding the project overrides maven dependency

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.

How to convert properly Eclipse project to Maven project?

I have created in Eclipse Dynamic Web Project. Then I have selected option 'Convert to Maven Project' from 'Configure' from right-click menu. And now I can see red errors on Java Resources folder in my project. But none subfolder is with red error. In which way can I resolve that problem? I am using Eclipse Juno and m2e plugin.
I have recognized that m2n plugin haven't created src/main/java, src/main/resources and src/main/webapp directories in Java Resources. But the error is still the same.
The process in manually. You need to create a pom.xml and change your folder structure to follow Mavens conventions. I would recommend to create a web project via maven archetypes and move your project step-by-step into the new structure.

Importing projects into Eclipse

I have this simple question how to import whole project source into Ecplise so I can browse it easily? Specifically, I have downloaded Maven source code http://maven.apache.org/download.html and I just want to view it same as other projects in my Eclipse.
I've tried to import it with use of two possible options (as archive and as a project) without luck.
Thank you in advance!
Maven itself is a Mavenized multi-module project, Generally there are two ways to import a Mavenized project into a IDE like eclipse:
Pre-requirment:
Suppose you have installed Maven 3 and setup environment variable
properly.
if you use Eclipse, you also need add M2_REPO to you
Build Path -- Classpath Variable, check out here for how to
setup. this tells Eclipse where to find jar dependencies stored in
local maven repository.
Option 1 -- Import as Java Project:
Open a command prompt and go to the extracted source folder, run mvn eclipse:eclipse
and waiting for it finish, make sure it doesn't popup any message start with [ERROR], this
will download all required jar dependencies from internet to you
local maven repository and create .project and .classpath for Eclipse
to use when doing import.
In eclipse, go to File -- Import -- General -- Existing Project into
Workspace, select the extracted source folder as root directory. This
will import a group of projects into Eclipse as bunch of regular java
projects (i.e. project icon inside Package Explorer watermarked with a
capital J).
Option 2 -- Import as Maven Project:
Alternatively, if yo got m2e plugin installed in Eclipse, you can
directly import the extracted project folder, go to File -- Import --
Maven -- Existing Maven Projects, select the extracted source folder
as Root Directory. This will import a group of projects into Eclipse
as bunch of Maven projects (project icon inside Package Explorer
watermarked with a Capital M).
Hope this helps.
The maven repository versions are not uploaded in the exact format they are on disc (from where the the mvn deploy goal is run. I can think of 3 options assuming I understand your question correctly:
You can find the open source project if it exists and get all the
source and project from there.
On an existing project, you go the dependencies, right click on one
and select browse source. Not the same as having the show project
here you can build and run however.
You can download the sources from the maven repo and then
reconstruct the project. I'm not not sure how feasible this
actually is and I have never tried it. I would probably find other
ways before trying this.