Create and Run Your First ZK Application with Gradle"
Robertwenzel (talk | contribs) |
Robertwenzel (talk | contribs) |
||
Line 64: | Line 64: | ||
http://localhost:8080/zk-gradle | http://localhost:8080/zk-gradle | ||
− | === Alternative method | + | === Alternative method: run embedded jetty directly === |
− | For shortest startup time an embedded jetty can be run directly | + | For shortest startup time an embedded jetty can be run directly from a main class [https://github.com/zkoss-demo/zk-gradle/blob/master/src/test/java/zk/gradle/test/RunJetty.java RunJetty] using a minimum configuration. |
./gradlew runJetty | ./gradlew runJetty | ||
− | After a short startup time you'll see this output and the server will run under the same URL | + | After a short startup time you'll see this output and the server will run under the same local URL. |
INFO: jetty-9.4.6.v20170531 | INFO: jetty-9.4.6.v20170531 | ||
Line 79: | Line 79: | ||
Press ENTER to exit ...... | Press ENTER to exit ...... | ||
+ | |||
+ | '''TIP''': this main class can naturally be executed directly in your IDE for easier debugging and even faster restarts | ||
== Import a Gradle project into your IDE == | == Import a Gradle project into your IDE == |
Revision as of 07:51, 20 July 2017
The zk-gradle example
The example project is located on github/zkoss-demo/zk-gradle. To use it all you need is a command line interface (and optional: git).
Since gradle is a complex tool a basic understanding about gradle itself will help understanding the example -> please refer to the gradle documentation pages.
Download/Clone the example project
With the git command line installed all you need is to clone the example repository:
git clone [email protected]:zkoss-demo/zk-gradle.git
Alternatively you can download the example as a zip-package.
Once cloned/unzipped open a command line in the project folder.
In order to get started immediately the project includes the gradle-wrapper. The wrapper comes with 2 scripts gradlew.bat (windows) and gradlew (linux/mac) and a folder /gradle containing a laucher jar which will download gradle itself with all its required dependencies without having to install gradle manually.
The first time you'll execute any of the commands in the following section gradle will download itself and all the required project dependencies. This will initially take quite a few minutes while showing the overall progress. Subsequent executions will be faster as gradle will cache the once downloaded resources in the .gradle/ subfolder (it's safe to delete this folder, gradle will just download the dependencies again next time it is executed)
build.gradle the build script [1]
settings.gradle the build settings e.g. contains the project name [2]
gradle.properties here contains the dependency versions [3]
Useful build tasks
NOTE: Using the windows command line (cmd) you have to omit the "./" in front of the commands e.g.
gradlew clean
build the war file (in the subfolder build/libs/zk-gradle.war)
./gradlew war
run the Zats Tests (also creates a test report in build/reports/tests/test/index.html)
./gradlew test
combine both
./gradlew test war
clean the build
./gradlew clean
list available tasks (shows many more options ...)
./gradlew tasks
Run the Project
The example project uses the gradle plugin gretty which launches an embedded jetty in its default configuration (it also supports tomcat):
./gradlew appRun
Once jetty is available you see the following output:
15:29:11 INFO Jetty 9.4.6.v20170531 started and listening on port 8080 15:29:11 INFO zk-gradle runs at: 15:29:11 INFO http://localhost:8080/zk-gradle Press any key to stop the server.
The server has started and you can access the test page under:
http://localhost:8080/zk-gradle
Alternative method: run embedded jetty directly
For shortest startup time an embedded jetty can be run directly from a main class RunJetty using a minimum configuration.
./gradlew runJetty
After a short startup time you'll see this output and the server will run under the same local URL.
INFO: jetty-9.4.6.v20170531 ... INFO: Started ServerConnector@97e93f1{HTTP/1.1,[http/1.1]}{0.0.0.0:8080} Jul 20, 2017 3:31:45 PM org.eclipse.jetty.server.Server doStart INFO: Started @1689ms Press ENTER to exit ......
TIP: this main class can naturally be executed directly in your IDE for easier debugging and even faster restarts
Import a Gradle project into your IDE
The example project doesn't include or require any IDE specific settings and can be imported into your preferred IDE supporting gradle.
In Eclipse you can use the buildship plugin
For IntelliJ IDEA just follow the Help page: Working with Gradle Projects