Maven Eclipse Plugin Doesn't Create Project Dependencies Properly - eclipse

Suppose I have a top level maven project with two modules:
moduleA
moduleB
and a groupId of my.group.
running mvn eclipse:eclipse on the parent project should generate eclipse files for all subprojects. The issue with this is that it doesn't include the groupId by default and only uses the artifactId.
So:
mvn eclipse:eclipse -Declipse.projectNameTemplate=[groupId].[artifactId]
This includes the group id in the project name, which is what the default behaviour should have been to begin with. Now the projects are named correctly in the .project files (my.group.moduleA, my.group.moduleB), but the .classpath files are all screwed up because they are still only using the artifactId and trying to reference projects moduleA and moduleB.
Am I missing something here or is this a bug in the maven eclipse plugin? It seems like a name change should propagate to everywhere the name is used. I.e. It should reference the project dependencies correctly and not require a bunch of manual classpath fixes inside eclipse that will get overwritten the next time mvn eclipse:eclipse is run.
The <name> element of the .project file gets set correctly, but it's using the wrong names in both the .classpath file and <projects> section of the .project file.
MVN Version: 3.2.5

The maven-eclipse-plugin is nowadays considered as abandonned. You better have to simply import your raw projects direcly from Eclipse (with m2eclipse installed) as Maven projects. Then the setup should be done properly.

Related

class test in an existing project j2ee converted to maven project

I'm a beginner in Maven and i have to "mavenize" an existing project for a company.
I opened the project in Eclipse and right click on the project -> Configure -> Convert to Maven Project.
So after that I didn't get the folders : src/main/java, src/main/resources, src/test/java, src/test/resources. I didn't get anything.
I have the m2e plugin and also Maven 3.3.3
I get the lib and Maven Dependency and arrange the pom.xml but i didn't have any test folder and any class Test so when running mvn:test i get no tests to run.
My question is : I have to create all the classTest manually ? Or Maven is supposed to create them automatically ?
Convert to Maven would normally:
configure the Maven Compile Plugin according to the JDK version in use by the original project
configure the build/sourceDirectory element (normally to src) instead of the standard src/main/java
ignore the bin folder used by default by Eclipse (so may see it in the Package Explorer and you can safely delete it)
Some manual steps are required (and suggested):
move the code to a newly created src/main/java folder and remove the build/sourceDirectory customization
remove the bin directory (it will now be target/classes)
Create src/main/resources folder and move any required resource (configuration file, etc.) to this folder
place your test sources under src/test/java, which you also need to create
if not the case, rename any test class to end by the *Test or *TestCase suffix so that by default the Maven Surefire Plugin will pick them up automatically (if not possible, alternatively you would need to configure it as described via official documentation here
If you don't have any test class yet, of course Maven would never create them automatically, you are responsible of writing your test cases, Maven would only run them.

Eclipse maven ear project deployment

I have a modular maven project.
On the top level I've got:
<modules>
<module>base</module>
<module>module1</module>
<module>module2</module>
<module>ear</module>
</modules>
The base module gets packed as a jar. module1 and module2 as war with a dependency on the base module. The Ear project has dependencies upon module1 and module2 and packages them accordingly. The pom's of module1 and module2 are exactly the same!!
Everything works perfect, except the deployment to the local server from eclipse. The problem is that module2 is missing base.jar in the lib folder of the deployed ear. Yet, module1 has it! If I run a mvn install from the command line it's also included in the target lib folder! In eclipse, all dependencies are resolved!
I've tried everything I can think of:
reimporting the projects,
cleaning all eclipse related files,
cleaning the local maven repository,
cleaning the servers tmp folder and re-add the projects,
do a maven update and install
Nothing helped so far.
Cheers
Edit:
I have made a somehow horrifying discovery:
I've added a module named "amodule". Guess what, it got the required jar and the others didn't. It seems like only the alphabetical first module gets the jar and the others don't.
My solution was to uncheck "resolve workspace dependencies" in the projects that include the base module. (project -> preferences -> maven -> uncheck: resolve workspace dependencies)
It comes with a side effect though: During debugging, the base.jar is handled like an external jar in the module. It is possible to specify the source code path, but I can't set a break point in the base project and wait until the debugger hits that line.

Maven Multiple module project in Eclipse issue

I have multiple module maven project which i imported in eclipse.
mvn eclipse:eclipse
and it shows child modules as following.
problem is it is not recognizing any of the child modules java files. if hover objects it does not show up any thing and consider as plain text files. it complains that it is not in build path ???
any idea how to fix or how to import multip modules maven project in eclipse.
Maven support is included in Eclipse Kepler. You can find it in the File -> Import screen as Maven -> Existing Maven Projects.
Selecting a directory with a parent POM in it will prompt you to import all its children as well.
If you really want to go down thatroad check out this old school method with eclipse:eclipse and multi-module import plugin.
But I have a different suggestion. Remove all eclipse:eclipse generated files, download m2e (new versions of Eclipse already include it). Then just use m2e Import Maven Project feature. It will recognize nested pom.xml files and let you create separate projects out of the ones you choose to work with.
Source: m2eclipse-book

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.

maven eclipse:eclipse - how to bring certain dependencies as jar files

I do have a multi module project out of which one references few others in the workspace. When I do maven eclipse:eclipse, it generates the .classpath with references to dependent projects as folder names (given below).
I understand that to generate all the dependent projects to be available as jar files in the classpath, we have to use 'useProjectReferences'. However, I need the classpath entry for child-project1 to be available as path to the jar file in the m2_repo and leave the classpath entry to child-project2 as reference to the folder.
Do a clean install of your referenced projects. Right click your parent project -> properties->maven, uncheck 'reference projects from workspace'. See if this works.