Eclipse 无法识别 src/main/webapp 目录
我使用 m2eclipse 在 Eclipse 中导入 Maven Java 项目。
它无法将 src/main/webapp 识别为源目录。
以图形方式在包资源管理器中(或者当我在项目属性中查看Java-Build-Path时),
该目录不在源文件夹列表中(而 src/main/java 或 src/main/resources 则在)。
要访问它,我必须直接查看 src/ 目录,然后开始展开...... 不是很方便!
但是,如果我运行 maven install
,资源将被复制到正确的目录。
(示例:src/main/webapp/index.jsp
到 target/mywar/index.jsp
)
问题
- 这是正确的行为吗? (我想它可以被视为其他资源......)
- 我可以修复它吗?
- 我想知道这种情况是否还有其他我现在没有意识到的缺点?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
也就是说,m2eclipse 做出了贡献,允许使用特定的“Web 资源”标签在顶层使用 src/main/webapp ,如下所示:
这可能是您担心的解决方案(折叠不方便)。
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).
不要将 /src/main/webapp 添加为 java 构建路径中的源文件夹,而是将其添加为要包含在部署程序集中的文件夹:
MyProject ->属性->部署程序集:将“/src/main/webapp”部署添加到“/”
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 "/"
就maven而言,
src/main/webapp
不是源文件夹,因为它的内容没有编译/复制到target/classes
,所以从 m2eclipse 的角度来看,这是正确的行为。您需要将 src/main/webapp 标记为 Eclipse 源文件夹是否有特殊原因?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 totarget/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?那么您只需将 src/main/webapp 标记为 Eclipse src 文件夹:
右键单击 webapp 文件夹 -->构建路径 -->用作源文件夹
不要认为您可以轻松地更改此行为而不需要任何丑陋的 hack,src 标记只是 Eclipse 特定的内容,它用于配置其类路径等。
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.
就我而言,Eclipse 无法将 src/main/webapp 识别为 Web 资源文件夹。我通过以下方式解决了这个问题:
In my case, Eclipse failed to recognise
src/main/webapp
as the Web Resources folder. I resolved it by:许多答案声称将 src/main/webapp 作为源文件夹没有意义,因为 JSP 文件是在构建周期中由容器而不是 Maven 编译的。
但是,当您进行安全测试时,它确实有意义:
一些安全扫描工具提供了可以集成到 IDE 中的插件,以便开发团队可以在本地扫描其代码并修复机器上的基本漏洞,从而减少安全团队的工作量,从而可以进行更高级的测试。
Eclipse 排除这个特定目录的事实是一个巨大的问题:通过这样做,安全工具默认情况下不会将
webapp/
目录包含到扫描过程中,这会导致漏报< /strong> (该工具未报告的实际漏洞)。这种行为会导致开发团队认为他们的 JSP 页面(例如)从安全角度来看是安全的。如果安全测试团队不关注开发团队进行的扫描(有时我们甚至无法检查哪些扫描是在本地进行的),则发布的产品更有可能存在
中包含的代码漏洞。 webapp/
文件夹。因此,从安全角度来看,这种行为没有意义,而且声称这种行为的人忽略了一些要点。
无论如何,我通过在
package explorer
中右键单击src/main/webapp/
文件夹将其添加到构建路径来解决了这个问题 -->构建路径
-->用作源文件夹
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 thepackage explorer
-->build path
-->use as source folder
一种解决方案是利用 m2e 对构建帮助程序 Maven 插件的支持,并将 src/main/webapp 声明为附加资源路径。这也使得 Eclipse 将保存的资源复制到构建目标文件夹结构中。
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.
我能想到一个理由。
我正在使用 Maven 在 Eclipse 中开发 GWT 项目。在我的配置中,src/main/webapp 目录包含我在开发工作中必须引用的 HTML 和 CSS 文件,即使它们不是“可编译”文件。
能够直接访问它们而不是深入到 src/ 文件夹是一个优点。在 POM 中定义它,以便以这种方式进行设置意味着我不必在每次运行 eclipse:eclipse 时手动添加该文件夹。
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.
就内斯特的观点而言,这不是开玩笑。它是一个端到端的开发环境,而不仅仅是一个编译器。它旨在作为所有源工件的接口,这些源工件有助于从 JSP 到构建配置(例如 POM 文件)。如果 XML 和 JSP 编辑器不能编译,为什么 Eclipse 还要麻烦它们呢? ——顺便说一下,这非常有用。
Eclipse 的 Maven 插件(反之亦然)非常棒,因为它构建了 .classpath、.project 以及立即开始在 Eclipse 中使用 Maven 项目所需的其他配置。但是,每次生成 eclipse 配置(即 mvn eclipse:eclipse)时,都必须手动添加不支持的目录。这真是太糟糕了。
事实上,这些插件忽略了轻松添加可从 IDE 中查看的新源文件夹的能力,这对我来说是一个谜。一个 maven/eclipse 插件项目页面甚至引用了通过切换项目类型和欺骗插件来使这些源暂时可用的解决方法——当然,您需要立即将其更改回来或损坏构建。
他们为什么不创建独立控制 .classpath 中源声明的能力???
To Nestor's point, no kidding. It's an end-to-end development environment and not just a compiler. It's intended as an interface for all source artifacts contributing to a build from JSP's to build configuration such as POM files. Why would eclipse even bother having XML and JSP editors if these aren't compile-able? --Which by the way, are super-useful.
The maven plugin for eclipse (or vice-versa) is terrific because it builds the .classpath, .project, and other configuration needed to immediately begin working with maven projects in eclipse. However, each time the eclipse config is generated (i.e. mvn eclipse:eclipse), unsupported directories must be added manually. That's a major suck.
The fact that these plugins neglect the ability to easily add new source folders viewable from within the IDE is a mystery to me. One maven/eclipse plugin project page even cites work-arounds for making these sources temporarily available by switching the project types and fooling the plugin--of course, you need to change it back immediately or corrupt the build.
Why don't they just create the ability to independently control the source declarations in .classpath???
对于我面临的同一问题,我发现了一个完全不同的原因 - 我在包资源管理器中看不到 src/main/webapp 。
结果发现它与 POM 或 Eclipse(使用 SpringSource Suite 3.5.0)能够加载 Maven 项目无关。
问题是我的 src/main/webapp/Scripts/ 文件夹中有 .git 和 .gitignore 文件。我怀疑 Eclipse 可能无法处理以“.”开头的文件名。在 webapp 文件夹中。我在多个项目中测试了这个理论,到目前为止它似乎站得住脚。
我希望这有帮助。
I found a whole different reason for the same problem I was facing - I would not see src/main/webapp in the package explorer.
Turned out it had nothing to do with either POM or with Eclipse (using SpringSource Suite 3.5.0) being able to load up maven project.
The problem was that inside my src/main/webapp/Scripts/ folder there were .git and .gitignore files. I suspect that may be Eclipse was not able to deal with file names begining with a "." in the webapp folder. I tested this theory across multiple projects and it seems to hold ground so far.
I hope this helps.