One of the nice features of RedHat JBoss Enterprise Application Platform is that you can script deployments and configurations using Jython. In this case we are using the Eclipse IDE together with the PyDev plugin for our development environment.
- Download and install the latest Java runtime from oracle.com if Java is not already on your workstation.
As a developer I would download the complete JDK (Java Development Kit) but Eclipse also runs fine with only the JRE (Java Runtime Environment). - Download the latest Eclipse from www.eclipse.org
- Install PyDev from within Eclipse via the Marketplace.
Eclipse / Help / Eclipse Market Place
Search for PyDev and install it - Download and install the latest Jython from jython.org
- Install/unzip JBoss EAP from for instance jboss.org
Now we can create a test program and configure Eclipse.
- Configure Jython in Eclipse via Window / Preferences / PyDev / Interpreters / Jython Interpreter
- Create a PyDev project in Eclipse
- Add the jboss-cli-client.jar from the JBoss bin\client directory to this project.
Via the Project Properties / PyDev – PYTHONPATH / External Libraries - Create a test file testscript.py
You can just ignore the error in the from clause regarding “as” because for python “as” is a reserved word. (By the way this took me some time to find out.)
import sys from org.jboss.as.cli.scriptsupport import CLI cli = CLI.newInstance() cli.connect() if cli.getCommandContext().isDomainMode() : cli.cmd("ls") cli.disconnect() sys.exit()
- Start JBoss in domain mode with the default settings and run the testscript.py via right-mouse-click Jython Run
You will see there is an error about a java.nio.charset.UnsupportedCharsetException
This error can be prevented when you use the “Run Configuration” and add for the VM arguments the property:
-Dpython.console.encoding=UTF-8
These are the basic steps for creating scripts for JBoss EAP in Jython. Hopefully this article will give you a jump start.
Another article about this can be found at developer.jboss.org