Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven webapp to place jsps in /WEB-INF/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</warSourceDirectory>
like image 811
Jacques René Mesrine Avatar asked Dec 09 '09 11:12

Jacques René Mesrine


2 Answers

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?

like image 149
Pascal Thivent Avatar answered Oct 03 '22 01:10

Pascal Thivent


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.

like image 20
Lumpy Oatmeal Avatar answered Oct 03 '22 01:10

Lumpy Oatmeal