I use m2eclipse to import Maven Java projects in Eclipse.
It fails to recognize src/main/webapp
as a source directory.
Graphically in the package explorer (or when I look into Java-Build-Path in the project's properties),
this directory isn't in the list of sources folder (while src/main/java
or src/main/resources
do).
To access it, I have to look directly into the src/ directory, and start unfolding... Not very convenient!
However, if I run maven install
, the resources are copied to the correct directory.
(example : src/main/webapp/index.jsp
to target/mywar/index.jsp
)
Questions
- Is this a correct behavior ? (I was thinking it could be treated as other resources ...)
- Could I fix it?
- I wonder if there are other drawbacks for this situation, that I would not be aware of right now?
Well you just have to mark the src/main/webapp as an Eclipse src folder:
right click webapp folder --> build path --> use as source folder
Don't think you can easily change this behavior without any ugly hacks, the src marking is just something Eclipse specific that it uses to configure its classpath etc.
Instead of adding /src/main/webapp as a source folder in the java build path, add it as a folder to include in the deployment assembly:
MyProject -> properties -> Deployment Assembly: Add "/src/main/webapp" deploys to "/"
That said, m2eclipse made a contribution that allows to make
src/main/webapp
available at the top level with a specific "Web Resources" label, something like this:This could be a solution for your concern (the not convenient folding).
In my case, Eclipse failed to recognise
src/main/webapp
as the Web Resources folder. I resolved it by:One solution is to exploit m2e support for build helper maven plugin and declare src/main/webapp as an additioanl resource path. This also makes eclipse copy saved resources to the build target folder structure.
I can think of a reason.
I'm using Maven for developing a GWT project in Eclipse. In my configuration, the src/main/webapp directory contains the HTML and CSS files that I have to refer to as part of my development effort, even though they're not "compilable" files.
Being able to get to them directly as opposed to diving into the src/ folder is a plus. And defining it in the POM so that it gets set up that way means I don't have to manually keep adding the folder every time I run eclipse:eclipse.