Grails and Maven Integration overview

Source: Internet
Author: User
Tags object model xmlns grails java web root directory

Overview

Grails Introduction: Grails is an open source WEB development framework that is developed with dynamic language Groovy and can be integrated with projects that are developed in Java. Grails fully embodies the principle of convention over configuration and minimizes the configuration of the project. The current mainstream Java WEB framework is too complex, such as Structs, Spring, WebWork, users of these frameworks need to write and maintain a number of configuration files, and use these frameworks for different project writing, there is no uniform standards. The presence of Grails solves these problems, and users can find that it is rare to modify and add configuration files in Grails.

Maven Introduction: MAVEN is a project management tool, based on the project object model, where MAVEN can manage the build, report, and document generation of projects. Maven is primarily used for projects that are developed in Java.

Grails support for Maven: Before Grails 2.1, Grails plug-ins must be in the Buildconfig.groovy file configuration, and Java dependencies must be specified in the Pom file.

After Grails 2.1, the support for Maven integration has improved greatly, and now the Pom file also supports referencing Grails plug-ins, as shown in Listing 1:

Listing 1. Pom.xml's support for Grails

<dependency> 
  <groupId>org.grails.plugins</groupId> 
   <artifactid>hibernate</ artifactid> 
   <version>2.1.0.RC1</version> 
   <type>zip</type> 
   <scope> Compile</scope> 
</dependency>

The Maven plug-in now recognizes other plug-ins and Jar packs that Grails relies on. And Grails adds a new command: Create-multi-project-build, which is called in a directory that includes multiple Grails applications or plug-ins, generates Maven constructs for complex projects. After Grails2.1, for Maven management of existing Grails projects, you only need to enter the Create-pom command to create the project's corresponding pom file.

Development environment: Grails 2.1, Maven 3, JDK1.6.

Integration of a single Grails project with Maven

Run the Create-app command first to build the Grails project, then generate the Pom file with the command Create-pom under the root directory of the Grails project. Specific examples are shown in Listing 2:

Listing 2. Generating pom files with command Create-pom

#> grails create-app my-app       
#> cd my-app       
#> grails create-pom build.groupid

We give a brief description of the above three commands, the first of which is the creation command for the Grails project, which will create the Grails application in the name specified by the user, and the name we specify is My-app, so it will be born into a grails application called My-app. The second command goes into the root directory of the My-app we created, because the third command needs to be run under the root directory of Grails. The third command is to create the POM file for the Grials application so that the Grails application can be built with Maven, and the parameter GroupID is the project that specifies the application affiliation.

After running the Create-pom command, we can see that the file Pom.xml was generated in the My-app root directory, as shown in Listing 3:

Listing 3. Pom.xml files generated in the My-app root directory

<?xml version= "1.0" encoding= "Utf-8"?> <project "xmlns="
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>   
    < groupid>build.groupid</groupid>   
    <artifactId>my-app</artifactId>   
    <packaging> grails-app</packaging>   
   <version>0.1</version>   
    <name>my-app</name>   
    <description>0.1</description> ... 
</project>

You can now run the MVN command to do a simple test, such as: MVN package, you can see the results as shown in Listing 4:

Listing 4. Run the MVN command to do a simple test

| Loading Grails 2.1.0 
| Configuring Classpath 
| Running pre-compiled script 
. 
| Environment set to prod .............. ........ 
... ... 
Packaging Grails Application ... 
| Compiling 1 source files ...... 
| Compiling 3 GSP files for package [myApp] 
... 
| Compiling 4 GSP files for package [databasemigration] 
... 
| Building WAR file .... .......................... ... 
| Done creating WAR Target\my-app-0.1.war 
[INFO]-------------------------------------------------------------- ---------- 
[INFO] Build SUCCESS 
[INFO]----------------------------------------------------------------  --------[INFO] Total 
time:2:13.841s 
[info] finished at:tue Oct 13:31:29 CST 
[info] Final Memory: 16m/34m 
[INFO]------------------------------------------------------------------------

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/extra/

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.