java maven webapp 将 jsps 放在 /WEB-INF/jsp 中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1873140/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
maven webapp to place jsps in /WEB-INF/jsp
提问by Jacques René Mesrine
I have inherited a webapp built using NetBean's internal ant.
我继承了使用 NetBean 的内部 ant 构建的 webapp。
All jsps reside in:
所有jsps驻留在:
WEB-INF/jsp
And the web.xml has hardcoded links to /WEB-INF/jsp/somefile.jsp
并且 web.xml 具有指向 /WEB-INF/jsp/somefile.jsp 的硬编码链接
How can I use the maven war plugin to place the JSP there, maintaining consistency with the current structure ?
如何使用 maven war 插件将 JSP 放置在那里,保持与当前结构的一致性?
My pom currently reads:
我的 pom 目前显示:
<warSourceDirectory>${basedir}/web/WEB-INF</warSourceDirectory>
回答by Pascal Thivent
What the problem? Let's look at a standard war project structure:
什么问题?让我们看一个标准的War项目结构:
$ mvn archetype:create -DgroupId=com.mycompany.app \
> -DartifactId=my-webapp -DarchetypeArtifactId=maven-archetype-webapp
...
$ tree my-webapp/
my-webapp/
|-- pom.xml
`-- src
`-- main
|-- resources
`-- webapp
|-- WEB-INF
| `-- web.xml
`-- index.jsp
5 directories, 3 files
No need to configure anything, just put your JSPs under src/main/webapp/WEB-INF/jspand there you go.
无需配置任何东西,只需将您的 JSP 放在下面src/main/webapp/WEB-INF/jsp即可。
EDIT:I don't understand why you have the following line in your maven-war-plugin configuration:
编辑:我不明白为什么您的 maven-war-plugin 配置中有以下行:
<warSourceDirectory>${basedir}/web/WEB-INF</warSourceDirectory>
What is the expected behavior? Why don't you use the default value ${basedir}/src/main/webapp?
什么是预期行为?为什么不使用默认值${basedir}/src/main/webapp?
回答by Lumpy Oatmeal
Also note that everything in src/main/resources will be "on the classpath", i.e., it all is copied to my-webapp/WEB-INF/classes when the war is built. So that's a good place to put your configuration files, for example, log4j.xml / logback.xml, or Spring's applicationContext.xml and Spring's other config files, which you can then easily reference with classpath:somefile.xml.
另请注意,src/main/resources 中的所有内容都将“在类路径上”,即,在构建War时,所有内容都将复制到 my-webapp/WEB-INF/classes。所以这是放置配置文件的好地方,例如 log4j.xml / logback.xml,或 Spring 的 applicationContext.xml 和 Spring 的其他配置文件,然后您可以使用 classpath:somefile.xml 轻松引用这些文件。
What also makes this very nice is you can set up filters in maven so that it transforms the files from src/resources before it puts them in the war file.
这也很不错,因为您可以在 maven 中设置过滤器,以便它在将文件放入 war 文件之前转换来自 src/resources 的文件。
So if you have any config files, other than web.xml, in src/main/webapp/WEB-INF, think about moving them to the src/main/resources directory.
因此,如果您在 src/main/webapp/WEB-INF 中有除 web.xml 之外的任何配置文件,请考虑将它们移动到 src/main/resources 目录。

