Search code examples
javamavendirectory-structure

what happens when we Build a java web project


I am a newbie to J2EE and I am not able to understand the directory structure created on building the java web project. After bit of googling I understood what we store in WEB-INF but

  1. I am not able to understand that what we store in META-INF?
  2. how target folder get created?
  3. where we mention that what all files should be placed in target folder?

I am using Maven to build the project which is a spring-hibernate based project.


Solution

  • 1) What's the purpose of META-INF?

    2) Maven creates the target folder for you. It's where all of the Maven plugins dump their work by default.

    3) Maven has mechanisms for excluding files from it.

    The key to understanding Maven is that Maven works on conventions. That means that Maven will do a lot of things really well with almost no effort on your part if you structure your project according to Maven's expectations. For example, this is how you differentiate between Java classes and resources in the source directory:

    src/main/java/com/mycompany/MyObj.java  
    src/main/resources/my/company/spring.context.xml  
    src/test/java/com/mycompany/MyObjTest.java  
    src/test/resources/my/company/spring.context.xml
    

    When you run mvn test it will compile all of that, move it appropriately over to the target folder, load the JUnit runner and give you a classpath that will let Spring have easy access to the spring context under the test folder. It'll run the tests and drop the reports under target.

    Maven is not like Ant. In Ant, you have to tell it everything. Maven works on the opposite end in that it assumes everything by default until you tell it otherwise.