This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes IDEs, Version Control and other tools and the fly likes m2eclipse: Resources not copied over to target folder Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "m2eclipse: Resources not copied over to target folder" Watch "m2eclipse: Resources not copied over to target folder" New topic
Author

m2eclipse: Resources not copied over to target folder

Maurice Huellein
Greenhorn

Joined: Jun 29, 2004
Posts: 5
Hi,

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:

http://wiki.eclipse.org/M2E_FAQ#Why_resource_folders_in_Java_project_have_excluded.3D.22.2A.22

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
build?

Thanks!
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5812
    
    7

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.


JBoss In Action
Maurice Huellein
Greenhorn

Joined: Jun 29, 2004
Posts: 5
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.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5812
    
    7

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.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15960
    
  19

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.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5812
    
    7

This Maven command will process the resources (it does everything short of compiling the Java sources):

mvn process-resources

You'd have to configure Eclipse for that goal, it's not one of the built-in ones.
Maurice Huellein
Greenhorn

Joined: Jun 29, 2004
Posts: 5
Hi all,

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)

 
wood burning stoves
 
subject: m2eclipse: Resources not copied over to target folder
 
Similar Threads
Change the location of persistence.xml in JPA (Eclipselink 2.3)
How can I get Eclipse, Maven and Glassfish work together while developing?
Eclipse problem regarding M2Eclipse/integrated web server
project structure for maven 2
help needed for building ejb project with maven