{"id":49,"date":"2016-07-09T14:30:04","date_gmt":"2016-07-09T12:30:04","guid":{"rendered":"http:\/\/www.petersplanet.nl\/?p=49"},"modified":"2016-07-09T20:49:22","modified_gmt":"2016-07-09T18:49:22","slug":"jython-scripting-for-jboss-eap-with-eclipse-and-pydev","status":"publish","type":"post","link":"https:\/\/www.petersplanet.nl\/index.php\/2016\/07\/09\/jython-scripting-for-jboss-eap-with-eclipse-and-pydev\/","title":{"rendered":"Jython scripting for JBoss EAP with Eclipse and PyDev"},"content":{"rendered":"<p>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.<!--more--><\/p>\n<ul>\n<li style=\"text-align: left;\">Download and install the latest Java runtime from <a href=\"http:\/\/java.oracle.com\">oracle.com<\/a> if Java is not already on your workstation.<br \/>\nAs a developer I\u00a0would download the complete JDK (Java Development Kit) but Eclipse also runs fine with only the JRE (Java Runtime Environment).<\/li>\n<li style=\"text-align: left;\">Download the latest Eclipse from <a href=\"http:\/\/www.eclipse.org\/\">www.eclipse.org<\/a><\/li>\n<li style=\"text-align: left;\">Install PyDev from within Eclipse via the Marketplace.<br \/>\nEclipse \/ Help \/ Eclipse Market Place<br \/>\nSearch for PyDev and install it<\/li>\n<li style=\"text-align: left;\">Download and install the latest Jython from\u00a0<a href=\"http:\/\/www.jython.org\/\">jython.org<\/a><\/li>\n<li style=\"text-align: left;\">Install\/unzip JBoss EAP from for instance <a href=\"http:\/\/www.jboss.org\/products\/eap\/download\/\">jboss.org<\/a><\/li>\n<\/ul>\n<p>Now we can create a test program and configure Eclipse.<\/p>\n<ul>\n<li>Configure Jython in Eclipse via Window \/ Preferences \/ PyDev \/ Interpreters \/ Jython Interpreter<\/li>\n<li>Create a PyDev project in Eclipse<\/li>\n<li>Add the jboss-cli-client.jar from the JBoss bin\\client directory to this project.<br \/>\nVia the Project Properties \/ PyDev &#8211; PYTHONPATH \/ External Libraries<\/li>\n<li>Create a test file testscript.py<br \/>\nYou can just ignore the error in the from clause regarding &#8220;as&#8221; because for python &#8220;as&#8221; is a reserved word. (By the way this took me some time to find out.)<\/li>\n<\/ul>\n<pre>import sys\r\nfrom org.jboss.as.cli.scriptsupport import CLI\r\n\r\ncli = CLI.newInstance()\r\ncli.connect()\r\n\r\nif cli.getCommandContext().isDomainMode() :\r\n    cli.cmd(\"ls\")\r\n\r\ncli.disconnect()\r\nsys.exit()\r\n<\/pre>\n<ul>\n<li>Start JBoss in domain mode with the default settings and run the testscript.py via right-mouse-click Jython Run<br \/>\nYou will see there is an error about a\u00a0java.nio.charset.UnsupportedCharsetException<br \/>\nThis error can be prevented when you use the &#8220;Run Configuration&#8221; and add for the VM arguments the property:<br \/>\n-Dpython.console.encoding=UTF-8<\/li>\n<\/ul>\n<p>These are the basic steps for creating scripts for JBoss EAP in Jython. Hopefully this article will give you a jump start.<\/p>\n<p>Another article about this can be found at <a href=\"https:\/\/developer.jboss.org\/wiki\/AdvancedCLIScriptingWithGroovyRhinoJythonEtc\">developer.jboss.org<\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[12,10],"class_list":["post-49","post","type-post","status-publish","format-standard","hentry","category-programming","tag-jboss","tag-jython"],"_links":{"self":[{"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/posts\/49","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/comments?post=49"}],"version-history":[{"count":14,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/posts\/49\/revisions"}],"predecessor-version":[{"id":64,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/posts\/49\/revisions\/64"}],"wp:attachment":[{"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/media?parent=49"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/categories?post=49"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.petersplanet.nl\/index.php\/wp-json\/wp\/v2\/tags?post=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}