The tool of the Novice tutorial use (ii)--maven a Web project that packages a non-canonical directory structure

Source: Internet
Author: User

People who have used Maven know that the directory structure of the MAVEN project is somewhat different from the traditional Dynamicweb project. Of course we do the best with Maven's specs, but what if you don't exactly follow Maven's specs and just need to use Maven to pack? In fact, it is simple, these can be changed by configuring the Pom file.


MAVEN Standard directory structure:

    myproject/      |--pom.xml      '--src          |--main          |   | --java          |   |   '--com          |   |       '--mycompany          |   | -Resources          |   '--WebApp          |       | --Web-inf          |       |   '--Web          |       '--index.jsp          '--Test              |--java              |   '--com              |       '--mycompany              '--resources  

above is a standard MAVEN directory structure, and regular Web project JSP, JS, CSS and other files are put into the webcontent/webroot. In Maven, these files are placed under WebApp. So, if you use Maven directly to install the package, your page related files will not be packaged in, you will find that the war package is only src. class files and some configuration files. So how to include pages and other files in it?


Very simply, you just tell Maven where your JSP is located and configure it as follows:

<build><finalName>projectName</finalName><plugins><plugin><groupId> Org.apache.maven.plugins</groupid><artifactid>maven-war-plugin</artifactid><version> 2.4</version><configuration><!--Specify the location of the Web. xml File--><webxml>webcontent\web-inf\web.xml </webXml><!--specify where files such as JSPs are located--   <warSourceDirectory>WebContent</warSourceDirectory> </configuration></plugin></plugins></build>

OK plus the above configuration, and then execute the install command, to be packaged, you will find that the WebContent files are all included in the war package. You can now copy the beaten war package to Tomcat and run it.


You might think that you'll have to manually copy the package to Tomcat, and you'll have to do it manually every time you pack it up. The next article will be with you to learn how to package with Maven and automatically deploy to Tomcat. A blog to learn a little better, we do not worry Oh!





The tool of the Novice tutorial use (ii)--maven a Web project that packages a non-canonical directory structure

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.