grails:using_console_to_create_and_build_a_project

Using Console to Create and Build a Project

  1. Assume the development environment has been set up correctly. If not go see Setup Grails 3 Development Environment.
  2. Check to the directory you want to work on. d:\grailsapp for example.
    C:\>d:
    D:\>cd\grailsapp
    D:\grailsapp>
  3. Create the app with the create-app command. The following code show how to create an app with name helloworld.
    D:\grailsapp>grails create-app helloworld
    | Application created at D:\grailsapp\helloworld
  4. We now have an new app under helloworld directory. We can cd in it, and start to work with it.
  1. Go to your project directory
  2. Type the command grails to enter Grails mode. It might take some time for Grails to download the libraries for the first time.
    D:\grailsapp\helloworld>grails
    
    BUILD SUCCESSFUL
    
    | Enter a command name to run. Use TAB for completion:
    grails>
  3. Grails, inherit from Spring Boot, has it own embedded Apache Tomcat. Thus it is a self-contained web-app.
  4. To run your app, type the command run-app
    grails> run-app
    | Running application...
    Grails application running at http://localhost:8080 in environment: development
    grails>
  5. Note that your app is now running in the back ground. You can stop your app by using command stop-app.
  6. To test the web-app, open a web browser and input the URL http://localhost:8080 as instructed. You should able to see the Grails welcome page.

There are three different versions of war file you can build, and they are the test, development, and production versions. In any case, the output war file will be located at YOUR_PROJECT_LOCATION\build\libs\YOUR_PROJECT_NAME_VERSION.war. You might deploy such war file to a Java Servlet Container such as Apache Tomcathttp://tomcat.apache.org/ or Undertowhttp://undertow.io/.

In grails mode, type test war

grails> test war
.
.
.
BUILD SUCCESSFUL

Total time: 5.634 secs
| Built application to build\libs using environment: test
grails>

In grails mode, type dev war

grails> dev war
.
.
.
BUILD SUCCESSFUL

Total time: 5.619 secs
| Built application to build\libs using environment: development
grails>

In grails mode, type prod war or assemble

grails> prod war
.
.
.
BUILD SUCCESSFUL

Total time: 5.447 secs
| Built application to build\libs using environment: production
grails>
  • grails/using_console_to_create_and_build_a_project.txt
  • Last modified: 2018/10/10 10:13
  • by chongtin