Saturday, 13 August 2016

Knowledge byte to validate content model without restarting Alfresco server

In any of your alfresco project, the first and very basic task that you do as a part of your technical implementation is, to start writing your content model as per your business requirement. Now, while doing so, there would be a point where you want to test if the content model xml that you have written is valid and are you able to successfully deploy it or not.

Generally, the common approach that you will take up is, deploy the content model xml and restart the alfresco server. While starting up the alfresco server, if there are any syntactical/schema errors, you will get to see those errors. Now, again you will make changes and again deploy it and restart the server until all the errors are gone and content model is successfully deployed and server is started. If you are a new developer to Alfresco, I am sure this is going to be the part of your story as I have seen many new developers facing this issue and spending their time there.

If you are seasoned alfresco professional, you must be already aware that there is a way to up-front test your content model without need of restarting server.

Let's take a look at how to validate your content model without the need to restart the alfresco server.

For example, you have created a content model named myContentModel.xml at the location
\tomcat\shared\classes\alfresco\extension inside your alfresco installed directory (We will take C:\Alfresco as an installed directory for example).

I am using windows OS and Alfresco Community edition 5.0.d.

Now, in order to test your content model, all you need to do is, Open command prompt, and execute the following command.

C:>java -cp "C:\Alfresco\tomcat\shared\classes;C:\Alfresco\tomcat\webapps\alfresco\WEB-INF\lib\*;C:\Alfresco\tomcat\webapps\alfresco\WEB-INF\classes" org.alfresco.repo.dictionary.TestModel alfresco\extension\myContentModel.xml

Once you execute the command, it will give the following result if the content model is valid, otherwise it will display the errors if its not valid.
Testing dictionary model definitions...

Models are valid.

This way you should be able to test your content model without the need of starting up the server and you will save a lot of time trial-and-error  making some minor changes to content model and restarting the server.

If you have not yet created your content model and you want to still test how the above command works then you can use an example content model shipped out-of-the-box by alfresco. It would be at
\tomcat\shared\classes\alfresco\extension\exampleContentModel.xml. It would be named as exampleContenteModel.xml.sample, you will have to just remove .sample and make it exampleModel.xml. In the above command, change the model file name at the end instead of myContentModel.xml to exampleContentModel.xml

While executing the command, If you face an error about log4j file then make sure you have given the appropriate permission. Another option is to run the command prompt as an administrator or another thing that you can try is give the absolute path to alfresco.log file in I am not going into the details here and just provided the few pointers you can try if you face log4j file related error. I am sure you must be able to figure it out based on it. If not, do drop a comment and I will help you solve that.

If you are using Linux then while specifying classpath use : instead of ; (I am sure as a first timer, you may spend a bit of time there as well in order to make a windows command work for linux)

Note : You may not find org.alfresco.repo.dictionary.TestModel class in some 4.x versions of Alfresco as it was accidentally removed from the relevant jar and later on was added back in the later versions.

Hope this blog will help you.

1 comment: