mkdir [dspace]/webapps/jython/
[dspace]/webapps/jython/
is used just to illustrate that the jython webapp is just another webapp like other DSpace webapps. It's possible to choose a different location - in fact, it's preferable because the [dspace]/webapps/
directory is replaced every time you run "ant update
" (the old webapps ditrctory will not be deleted, it will be renamed to "webapps-[timestamp]").jython-installer-2.7.0.jar
) from http://www.jython.org/downloads.htmljython.jar
and the Lib
directory.unzip -d [dspace]/lib/ jython-installer-2.7.0.jar jython.jar Lib/
unzip -d [dspace]/webapps/jython/WEB-INF/lib/ jython-installer-2.7.0.jar jython.jar Lib/
java -jar jython-installer-2.7.0.jar --console
jython.jar
and Lib
Associate .py files with Jython's PyServlet
<web-app> <servlet> <servlet-name>PyServlet</servlet-name> <servlet-class>org.python.util.PyServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>PyServlet</servlet-name> <url-pattern>*.py</url-pattern> </servlet-mapping> </web-app> |
Create a Hello World servlet:
# -*- coding: utf-8 -*- from javax.servlet.http import HttpServlet class hello(HttpServlet): def doGet(self, request, response): self.doPost(request, response) def doPost(self, request, response): toClient = response.getWriter() toClient.println('Hello World!') |
cp -r [dspace]/lib/* [dspace]/webapps/jython/WEB-INF/lib/
Start up DSpace kernel on webapp startup and point it to your DSpace configuration:
<web-app> ... <!-- DSpace Configuration Information --> <context-param> <param-name>dspace-config</param-name> <param-value>/dspace/config/dspace.cfg</param-value> </context-param> <!-- new ConfigurationService initialization for dspace.dir --> <context-param> <description>The location of the main DSpace configuration file</description> <param-name>dspace.dir</param-name> <param-value>/dspace</param-value> </context-param> <listener> <listener-class>org.dspace.app.util.DSpaceContextListener</listener-class> </listener> <listener> <listener-class>org.dspace.servicemanager.servlet.DSpaceKernelServletContextListener</listener-class> </listener> </web-app> |
Define the context in Tomcat's configuration. There are several ways how you can do that, so just use the same way you use for configuring DSpace contexts. The recommended one is to use a context fragment:
<Context docBase="/dspace/webapps/jython" reloadable="true" cachingAllowed="false" /> |
A few seconds after you save the file, Tomcat will notice it and load the "jython" context.
/dspace/webapps/jython/WEB-INF/lib/
sudo touch /etc/tomcat7/Catalina/localhost/jython.xml
Tip: If you forgot which libraries you added (because it's hard to spot them among dozens of libraries which belong to DSpace), here's how you can filter out the DSpace libraries, which should leave you only with a list of libraries you added:
ls -1 /dspace/webapps/jython/WEB-INF/lib > /tmp/jython.txt ls -1 /dspace/lib > /tmp/dspace.txt diff -u /tmp/jython.txt /tmp/dspace.txt | view - |
Python libraries can either be added to /dspace/webapps/jython/WEB-INF/lib/Lib/
or to context root (/dspace/webapps/jython/
).
<web-app> ... <servlet-mapping> <servlet-name>SherpaRomeo</servlet-name> <url-pattern>/SherpaRomeo</url-pattern> </servlet-mapping> </web-app> |