Work with Maven: Create a project skeleton

Source: Internet
Author: User
Tags xmlns

The

has been built with Maven as a project, and Maven is easier to use than ant, at first to not want to spend more effort on Ant's Build script, to choose Maven, but then the practice proves that the choice is correct, then the time and effort is saved, It turns out that I didn't save much time by choosing Maven, and it was worth the time and effort in building the build tools, but Maven gave me a lot more than I expected. What

Maven can do. Basically, the maven that ant can do can do it and do it better in many places. Why do you say that, do not talk about the theory, with the facts proved. Struts2,webwork2,spring2,appfuse2 and other more weight items can see Maven figure. Another of his biggest features is its reliance on package management systems, which is not a new concept, and debian/ubuntu,ruby-gems use similar ideas to manage the dependency packages/libraries.

After familiar with Maven2 project configuration file, can not write a line build script, just more than 10 lines of step by step to rely on the package configuration, you can complete a complete Web project compilation, testing, packaging, cleanup and other tasks, but if you want Maven to do more, follow me ...

Start with one of the simplest web projects, assuming the project name is called myweb,jdk1.5 above, the Linux system (XP is used the same way, except that the XP cmd is too bad, no Linux console to use, or I am too vegetable, Not with XP Advanced CMD command line interface).
1)   Install MAVEN, install the process slightly, just like you do ant, official website http://maven.apache.org
2)   Build a project skeleton, open a linux console command-line window, Enter the following command: Java code mvn archetype:create /  -dgroupid=com.mycompany.webapp /  - Dartifactid=myweb/  -darchetypeartifactid=maven-archetype-webapp  


Simply explain:
Archetype is a built-in plugin that creates a project skeleton for his create task
Archetypeartifactid type of Project skeleton

The available project skeletons are:
* Maven-archetype-archetype
* Maven-archetype-j2ee-simple
* Maven-archetype-mojo
* Maven-archetype-portlet
* Maven-archetype-profiles (currently under development)
* Maven-archetype-quickstart
* Maven-archetype-simple (currently under development)
* Maven-archetype-site
* Maven-archetype-site-simple, and
* Maven-archetype-webapp

Java package structure of the GROUPID project, which can be modified
The name of the Artifactid project, which is also the name of the generated project directory, can be modified

A MyWeb folder is generated under the current directory, which is our project folder.

3) Complete the directory structure of the project, because the resulting project skeleton is a webapp minimized skeleton structure, with the MAVEN standard project layout There is still a gap,
MAVEN standard project layout structure see http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html
In fact, you have to manually set up a few directories, the following command is all done Java code mkdir-p Src/{main/java/com/mycompany/webapp,test/java/com/mycompany/webapp, Test/resources}


4)   Add an embedded servlet/jsp container jetty6, with NIO rewritten embedded server, development and debugging Web project very convenient, here need to edit the unique configuration file Pom.xml, it is not difficult in fact XML code   < Project   xmlns = "http://maven.apache.org/POM/4.0.0"   xmlns:xsi = "http://www.w3.org/2001/ Xmlschema-instance "     xsi:schemalocation =" http://maven.apache.org/POM/4.0.0 http:// Maven.apache.org/maven-v4_0_0.xsd ">      < modelversion > 4.0.0 modelversion >  & nbsp   < groupId > Com.mycompany.webapp groupId >      < artifactid > MyWeb artif Actid >      < Packaging > War packaging >      < version > 1.0- SNAPSHOT version >      < name > Myweb maven webapp name >     & nbsp;< url > http://maven.apache.org url >      < dependencies >    &NBSP;&N bsp;  < dependency >          < groupId > JUnit groupId >          < Artifactid > JUnit artifactid >          < version > 3.8.1 version &G T          < scope > Test scope >         Dependency >       dependencies >      < build >     & nbsp;  < finalname > MyWeb finalname >  

< plugins > < plugin > < groupId > Org.mortbay.jetty groupId > < AR Tifactid > Maven-jetty-plugin artifactid > Plugin > Plugins >

Build > Project >


5) Run Test Java code MVN jetty:run

In the case of network uptime, Maven automatically downloads all jar dependencies and then launches Jetty6, which can be accessed in the browser http://localhost:8080/myweb/
Jetty6 has been started and shows the classic-to-dregs " Hello world! "
can now modify the src/main/webapp/index.jsp, and then in the browser refresh to see the effect, the simplest web skeleton is born of
the command to stop Jetty6 is CTRL + C

, You can add SPRING,HIBERNATE/IBATIS,STRUTS/STRUTS2/WEBWORK2 and Report,xdoclet,hibernate code generation tools in Pom.xml, Dbunit, etc... (wrote here today, later in writing.)

Two articles are recommended:
http://www.blogjava.net/calvin/archive/2006/03/19/36098.html
http://www.ibm.com/ developerworks/cn/opensource/os-maven2/

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.