src/main/webapp directory not recognized by Eclipse
Solution 1
- 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?
- Yes, to me this is the correct behavior.
- It doesn't really make sense for src/main/webapp to be a source folder, it doesn't contain compilable source files.
- I don't know. I guess it depends on your expectations :)
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).
Solution 2
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 "/"
Solution 3
As far as maven is concerned, src/main/webapp
isn't a source folder in the sense that it's contents aren't compiled / copied to target/classes
, so from m2eclipse's point of view, this is correct behaviour. Is there a particular reason you need src/main/webapp to be marked as an Eclipse source folder?
Solution 4
In my case, Eclipse failed to recognise src/main/webapp
as the Web Resources folder. I resolved it by:
- Deleting the project
- Restarting eclipse
- Taking a fresh update of the Maven project form the SVN.
Solution 5
Many answers claim that it doesn't make sens to have src/main/webapp
as a source folder because JSP files are compiled by the container and not maven during build cycle.
However, it does make sense when you're doing security testing:
Some security scanning tools provide plugins that can be integrated into IDEs so that development teams can locally scan their code and fix basic vulnerabilities on their machine, thus reducing the amount of work for security teams that can therefore work on more advanced testing.
The fact that Eclipse excludes this specific directory is a huge problem: by doing that, security tools won't include by default the webapp/
directory into the scan process, which results in false negatives (actual vulnerabilities that aren't reported by the tool). This behavior then leads development teams into thinking that their JSP pages (for example) are safe from a security point of view.
If security testing teams don't pay attention to the scans conducted by development teams (sometimes we can't even check which scans have been performed locally), the product is more likely to be released with vulnerabilities in code contained in the webapp/
folder.
Thus, this behavior doesn't make sense from a security point of view, and people claiming it does are missing some points.
In any case, I solved this problem by adding the src/main/webapp/
folder to the build path by right clicking it in the package explorer
--> build path
--> use as source folder
CppDude
Updated on July 09, 2022Comments
-
CppDude almost 2 years
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 (whilesrc/main/java
orsrc/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
totarget/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?