I have the feeling that I am not using the m2 plugin correctly to build my projects. The problem is, that the resources folders are not copied over when Eclipse rebuilds.
To give an example: I have a maven project with a META-INF folder in the resources folder that holds the spring application contexts. When I rebuild (e.g. eclipse project clean)
from scratch, the classes get compiled properly, but the META-INF folder is not copied. The project setup shows indeed that there is a '**' exclusion filter for the resources.
That brought me to that explanation:
The effect is that e.g. my Integration tests do not run, because they don't find the application contexts in the target folder. If I build the project from the command line, the maven
builder kicks properly in and copies those resources over.
So what is the intended way to let Eclipse automatically build and copy the project into the target folder so that everything is available? Or is the only way to manually do a maven
Is your Eclipse project a Maven project? And do you build it by choosing Run As | Maven Build? If you do, then mvn should be run to perform the build, and the resources will get copied. (The link you provider seems to imply that Eclipse doesn't copy resources because Maven will.) None of my team members have complained about resources not being copied (and believe me, they would let me know if that was the case), and I know they all do builds within Eclipse. Personally, I value my sanity and always build from the command line.
Hi Peter, thanks for your reply. No, actually I do not execute it via the maven menu. The occasion when I am annoyed most
by this behaviour is actually not when I want to cleanly build and run the application, but when I want to run the integration tests.
Eclipse manages most of the necessary things: dragging automatically all dependencies in (and updating them), rebuilding the
classes, checking versions of the dependencies ... so there would be no need to configure a maven run setting if it would properly
copy the resources.
Actually this is even more annoying, as there is an inconsistent behaviour that made it hard for me to exactly spot what is going wrong:
If you build your project via maven (either by command line or eclipse), the target folder is prepared properly. You can clean and rebuild
the eclipse project (using the clean project option or just relying on the auto compile) and the resources stay in the target folder. As a
result, the application/test will work.
If now an svn change comes in and you update, it seems that the target folder gets wiped out, so the rebuild of the projects only creates
the classes new, but the resources are gone.
For me it makes no sense and I would like to have the auto-build function of eclipse manage the resources as well - and especially
as it does normally.
I think the issue you are having is that Eclipse has no idea whatsoever as to what Maven is attempting to accomplish, because it has an entirely different concept of how builds are done than what Maven does. Then it looks like when you do an update, a Maven clean is run automatically (seem like some m2e and subclipse integration, though I thought that was dropped a while back). So unless Maven does the build again, the target folder will not get populated with everything (I believe that Eclipse has no concept of "resources" like Maven has). As far as I know, there is nothing that you can do about this.
Personally, I avoid letting Eclipse build my project at all costs; usually it ends up messing things up. I stick with letting Maven do the building and test running. I have even convinced my co-workers who insist on doing things within Eclipse to use the Run as | Maven xxx menu entries to get their work done.
I too run Maven explicitly within Eclipse. The Eclipse builders are a simplistic lot that are OK for basic stuff, but when I want an actual artefact, I invoke Maven myself. The Eclipse builders don't do that. For one thing, since Maven has many, many potential goals, it would be hard-pressed to pick which one to use for automated updating. I bounce between 3-4 separate goals myself on a typical project job.
You could, of course, automate the resource copying process by following the instructions in the link you supplied. Of course, if you do that, it will be a "dumb" copy without the ability to do Maven-enhanced things like variable substitution into selected resources. There's no single "copy resources" Maven goal that I can think of, so Eclipse wouldn't be able to work that way. However, even if there is such a goal, Eclipse executes Maven the same way it runs/debugs any other app in the Eclipse workspace, which is a far more heavyweight operation than what the builders do.
Customer surveys are for companies who didn't pay proper attention to begin with.
This Maven command will process the resources (it does everything short of compiling the Java sources):
You'd have to configure Eclipse for that goal, it's not one of the built-in ones.
Joined: Jun 29, 2004
thanks for the help and explanations. Actually I understand the problem that Eclipse has no native understanding
of the maven build process, but isn't that the reason why we use m2eclipse? I think it is a pretty straight forward
task to see the copy of the resources as part of the eclipse build process (I mean, the standard maven project
does not disable the compilation of the classes either - although it should solely be controlled by maven)
subject: m2eclipse: Resources not copied over to target folder