March 06, 2015

Alfresco: How to write a simple Java based Alfresco web script?

If you want to develop new feature for Alfresco best way is WebScript! Let's start with a simple Alfresco web script. First you need to create an Alfresco AMP maven project using archetype. In this example I'll use the latest alfresco version 5.0.

First I generated Alfresco All-in-One AMP. (Please refer my blog post on generating AMP projects.)

If you go through the files structure which is generated, you will find out a sample web script. It is a JavaScript based WebScript. By this example, I'm going to explain how to write a simple Java based Hello World web script.

HelloWorldWebScript.java service-context.xml helloworld.get.desc.xml helloworld.get.html.ftl
Create above files in below locations of your maven project.
  • HelloWorldWebScript.java - repo-amp/src/main/java/org/dedunu/alfresco/HelloWorldWebScript.java
  • helloworld.get.desc.xml - repo-amp/src/main/amp/config/alfresco/extension/templates/webscripts/org/dedunu/alfresco/helloworld.get.desc.xml
  • helloworld.get.html.ftl - repo-amp/src/main/amp/config/alfresco/extension/templates/webscripts/org/dedunu/alfresco/helloworld.get.html.ftl
  • service-context.xml - repo-amp/src/main/amp/config/alfresco/module/repo-amp/context/service-context.xml
Use below command to run the maven project.

mvn clean install -Prun 

It may take a while to run the project after that open a browser window. Then visit to below URL

http://localhost:8080/alfresco/service/dedunu/helloworld.


3 comments:

  1. Thanks a Lot for very useful tutorail.
    It helps me to kickstart Java Backed web script
    for integration test i used below command

    mvn integration-test -Pamp-to-war -Dmaven.tomcat.port=8081

    Thanks a lot again for all your time writing good posts like this.

    ReplyDelete
  2. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training India . Nowadays Java has tons of job opportunities on various vertical industry.

    ReplyDelete