开发者

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

开发者 https://www.devze.com 2022-12-13 10:50 出处:网络
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

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</warSour开发者_运维问答ceDirectory>


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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消