Eclipse and Maven configuration - eclipse

I'm new to Maven. I've just installed and configured it.
When I started coding, I realized Eclipse doesn't show the error messages.
I haven't found anything helpful by searching Google. Some sources say to add java builder to your project but I already did.
Here's a screenshot.

It looks, that you had project in eclipse configured to have source code in 'src' subdirectory (and compile classes to 'bin').
Maven by default looks for java sources in src/main/java (and compile classes to 'target/classes').
So you'd need to move your source code to src/main/java or modify pom.xml to point to 'src' as source directory.
I'd suggest following maven convention and store source code in src/main/java.

You didn't create the Maven standard folder structure.
Create the structure like that:
src/main/java for Java classes and src/main/resources for properties etc., then do a right click on the project and choose Maven -> Update project configuration.

Related

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.

Eclipse doesn't compile classes in source/main/resources directory in maven project

I have created a maven project in eclipse using the maven2eclipse plugin.
I then convert the project to a web module project by going to project facets in the project properties.
The problem is that when I attempt to create a class under the directory src/main/resources, none of my classes compile. I can put any sort of junk in the classes and the compiler doesn't give me any warnings. Also, the package I create doesn't create a "brown package" but a folder instead.
Does anyone know what I have configured wrong?
src/main/resources is intended to hold... resources: properties files, images, etc. that are copied to the classes directory. Java source files must be put in src/main/java.
You can try this : right click on your project > maven > update project configuration. It will configure you .classpath and .settings against your pom.xml configuration.
The problem was that when you switch to this web module in project facets, the "exclude *.java" files is entered under java build path > source by default. This must be removed.

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.

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.