maven webapp to place jsps in /WEB-INF/jsp

流过昼夜 提交于 2019-12-03 14:08:53

问题


I have inherited a webapp built using NetBean's internal ant.

All jsps reside in:

WEB-INF/jsp

And the web.xml has hardcoded links to /WEB-INF/jsp/somefile.jsp

How can I use the maven war plugin to place the JSP there, maintaining consistency with the current structure ?

My pom currently reads:

<warSourceDirectory>${basedir}/web/WEB-INF</warSourceDirectory>

回答1:


What the problem? Let's look at a standard war project structure:

$ 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/jsp and there you go.

EDIT: I don't understand why you have the following line in your maven-war-plugin configuration:

<warSourceDirectory>${basedir}/web/WEB-INF</warSourceDirectory>

What is the expected behavior? Why don't you use the default value ${basedir}/src/main/webapp?




回答2:


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.

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.

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.



来源:https://stackoverflow.com/questions/1873140/maven-webapp-to-place-jsps-in-web-inf-jsp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!