Domanda

I'm new to groovy and ratpack. I have read that i can simply put my entire application in a file and run it like a simple groovy script groovy filename.groovy. When I run one example script nothing seems to happen and pointing the browser to localhost:5050 has no effect... I'm sure I'm missing something big...What I have to do in order to get started? Do I need to start the application in some way, other than running the script?

@GrabResolver("https://oss.jfrog.org/artifactory/repo")
@Grab("io.ratpack:ratpack-groovy:0.9.0-SNAPSHOT")
import static ratpack.groovy.Groovy.*

ratpack {
    handlers {
        get {
            response.send "Hi!"
        }

        assets "public"
    }
}
È stato utile?

Soluzione

Use latest versions of ratpack (0.9.2[released today] or 0.9.1). They seem to work the way you are trying to use.

@GrabResolver("https://oss.jfrog.org/artifactory/repo")
@Grab("io.ratpack:ratpack-groovy:0.9.2")
import static ratpack.groovy.Groovy.*

ratpack {
    handlers {
        get {
            response.send "Hi!"
        }

        //assets "public" //Not required if there is no asset to refer to 
    }
}

You can also run the script from groovyConsole to start the server.

Running as a script is a good starting point. Using ratpack for projects, I suppose a good staring point will be to use gradle as well, with something like below as the project structure.

 -- client  
 -- server
     |_ src  
         |_ ratpack  
            |_ ratpack.groovy  
     |_ build.gradle

You can effectively use ratpack-groovy plugin in gradle if you are already familiar with gradle and opting to use it. Here is an example app of using ratpack gradle plugin in a ratpack app. Another example where you can see usage of ratpack (server), mongo (db) and AngularJS (as client)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top