Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Maven know where to put the source file under the exploded directory?

Tags:

java

maven

I am learning maven , though worked on ant in past.

I have am just trying to figure out what happens when command mvn install or mvn compile is executed. I am mainly interested how project is built like location of resources to pick for build and where to put them once built

My project source structure is

src > main > java > java files
src > main > resources > reources like spring config atc
src > main > webapp > static files like js,css etc
src > main > webapp > WEB-INF > web.xml and jsp files

Once i give mvn package or mvn clean i see below exploded directory(my focus is on this) with name myProject alongwith other files lile war, classes etc. Explode structure for myProject is

1) All files from (src > main > webapp) including WEB-INF gets copied under myProject
2) All files from (src > main > resources) gets copied under myProject > WEB-INF/Classes
3) All files from (src > main > java) gets copied under myProject > WEB-INF/Classes

As per my understanding when we give any of mvn install or mvn compile or mvn package all compile phases gets executed. But My question is how Maven know where to put the source file under exploded directory. Is it a standard maven follows?

Here is snippet for reference from pom.xml i am using

<artifactId>myProject</artifactId>
    <packaging>war</packaging>
    <name>myProject</name>
.....

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>exploded</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <overlays>

                    </overlays>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.alchim31.maven</groupId>
                <artifactId>yuicompressor-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>jslint</goal>
                            <goal>compress</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <aggregations>
                    </aggregations>
                </configuration>
            </plugin>
        </plugins>
    </build>
like image 222
M Sach Avatar asked Dec 05 '25 08:12

M Sach


1 Answers

Maven follow Java standard when it put compiled files in WEB-INF/classes.

Illustration from the The Java EE 6 Tutorial

This directory contains server-side classes: servlets, utility classes, and JavaBeans components. These classes are only visible to the servlet and are not public.

From Java Servlet 3.1 specifications :

10.5 Directory Structure

A special directory exists within the application hierarchy named “ WEB-INF ”. This directory contains all things related to the application that aren’t in the document root of the application. Most of the WEB-INF node is not part of the public document tree of the application. Except for static resources and JSPs packaged in the META- INF/resources of a JAR file that resides in the WEB-INF/lib directory, no other files contained in the WEB-INF directory may be served di rectly to a cl ient by the container. However, the contents of the WEB-INF directory are visible to servlet code using the getResource and getResourceAsStream method calls on the ServletContext , and may be exposed using the RequestDispatcher calls. Hence, if the Application Developer needs access, from servlet code, to application specific configuration information that he does not wish to be exposed directly to the Web client, he may place it under this directory.

like image 109
alain.janinm Avatar answered Dec 07 '25 22:12

alain.janinm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!