What is Groovy Script: Apache Groovy is an Object-oriented programming language used for the Java platform. It can be used as a scripting language for the Java platform.
Groovy vs Java
Groovy vs Java | Groovy | Java |
Definition | It is compiled to JVM bytecode and is compatible with the Java Platform. | It is developed on JDK and is run on JVM. |
Usage | It is used when both programming language and scripting language. | It is used as a programming and object-oriented language. |
Integration | It can be integrated along with any web applications and scripting applications. | It can also be integrated with any object-oriented application as it is compatible with any JVM based applications. |
Platform | It supports any operating systems or platforms | It supports cross-platform operating systems |
Syntax | The syntax is very similar to Java syntax. | It has a strong disciple in its syntax. |
Community | It has been submitted to JCP for specification request. | It has a larger community called Java Community process i.es JCP being maintained by a large group of highly qualified technical experts across the industry. |
License | It was licensed under Apache license 2.0 | It was licensed under GNU General Public License. |
Imports | All the packages will be imported by default. | It has to be mentioned clearly to import any package into the java class file. |
Documentation | It provides single page documentation. | It has documentation in the form specification given by JCP. |
Download the Groovy Console package. Check the version compatible with your AEM instance. For AEM 6.5 I am using the 14.0.0 version.
Install the downloaded package using the CRX package manager.
To verify the installation, open http://localhost:4502/apps/groovyconsole.html in the browser to view the groovy console.
Note: From 13.0.0 release, paths were changed from /etc/ to /apps/ to access Groovy Console
GUI Console:
Sample scripts are available in the Groovy Console.
Open any script and click on Run Script.
If you get an error when running scripts, add user group in Allowed Group property of "Groovy Console Configuration Service".
GUI Console:
Sample scripts are available in the Groovy Console.
Open any script and click on Run Script.
If you get an error when running scripts, add user group in Allowed Group property of "Groovy Console Configuration Service".
Sample Script:
The above script will pull the pages which have the property "hideInNav" as false from the Weekend Event site.
getPage("/content/wknd-events").recurse { page ->
def content = page.node
if (content && !content.get("hideInNav")) {
println page.path
}
}
The above script will pull the pages which have the property "hideInNav" as false from the Weekend Event site.
No comments:
Post a Comment
If you have any doubts or questions, please let us know.