7

I have a Django app we're attempting to deploy to a Tomcat server, using django-jython.

Just to test things, I've created the WAR archive file for a empty Django app successfully. The test Django application is called "chair".

Our Tomcat server apparently doesn't like WAR archives files, so I exploded (unzipped this), and copied these files to the server.

The webserver admin has created a context for me, and a directory for that context (mediatracking).

I've copied the files from the WAR archive into that directory, and I'm not quite sure how to get that test app to "run" now?

\mediatracking
 - application.py 
 - application$py.class 
 \WEB-INF 
   web.xml 
   \lib 
    - jruby-extras-fileservlet.jar 
    - jython.jar 
   \lib-python 
     - Lib.pth 
     - README 
     \chair 
     \django 
     \doj 
     \Lib 

etc. (I haven't descended lower than that in the chair/django/doj/Lib directory.)

Is there anything obvious missing from the above directory structure?

And how exactly do I get the Tomcat server to actually "run" this app? It doesn't run automatically if you go to the context directory (and there's only a application.py and application$py.class file there, so I'm not sure how it would).

Do I need to ask my webserver admin to do something with the web.xml file? I checked that, and there doesn't seem to be anything in there that would help this app run either:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
  <display-name>chair</display-name>
  <description>
   chair through WSGI with modjy
  </description>
  <context-param>
    <param-name>files.prefix</param-name> <!-- Needed by fileservlet -->
    <param-value></param-value>
   </context-param>
  <servlet>
    <servlet-name>modjy</servlet-name>
    <servlet-class>com.xhaus.modjy.ModjyJServlet</servlet-class>
    <init-param>
      <param-name>reload_on_mod</param-name>
      <param-value>1</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet>
    <servlet-name>fileservlet</servlet-name>
    <servlet-class>org.jruby.webapp.FileServlet</servlet-class>
  </servlet>


  <servlet-mapping>
    <servlet-name>fileservlet</servlet-name>
    <url-pattern>/media/*</url-pattern>
  </servlet-mapping>

  <servlet-mapping>
    <servlet-name>modjy</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>
</web-app>

Any advice at all would be greatly appreciated =).

Cheers, Victor

victorhooi
  • 16,775
  • 22
  • 90
  • 113

2 Answers2

2

This is a late answer, but I hadn't seen this question so far. Hope it still helps. Here are the steps I always follow (successfully).

1) Create the war file:

manage war --include-java-libs "...your external jars here..." --context-root=chair

The name of context-root is important because Django-on-Jython will manipulate your settings.py file and modify your MEDIA_URL and ADMINMEDIA_URL to add that context (e.g. MEDIA_URL = '/chair/media/'), and it must be the same context that you deploy to in Tomcat. It will be the same name of the generated war file (in this case chair.war). In external JARs include at least your JDBC drivers.

2) Deploy the war to Tomcat (has never been a problem in any Tomcat I used, versions 5 and 5.5). I do it manually through the HTML manager app at URL http://server:8080/manager/html - it will require authentication, use a username/password that has manager privileges in Tomcat's conf/users.xml I think (I'm writing from memory). There are plenty ways to automate this with Ant, Maven or other tools, but manual is just fine.

If you absolutely have to unwar the file manually, use a folder name that is exactly the same of the war file (and thus the context-root), in this case webapps/chair in the Tomcat install folder.

3) Access your deployed app from URL http://server:8080/chair/ (plus any additional url path as defined in urls.py)

The Modjy servlet is the one running serving your urls, as defined in:

  <servlet-mapping>
    <servlet-name>modjy</servlet-name>
    <url-pattern>/*</url-pattern>
  </servlet-mapping>

If you don't see what you expect at http://server:8080/chair/ check in the HTML manager whether the app was really started, and check your Tomcat logs for errors (typically logs/catalina.out at the tomcat installation dir).

More info in the official doc: http://packages.python.org/django-jython/war-deployment.html

Carles Barrobés
  • 11,608
  • 5
  • 46
  • 60
  • For me, this error came after deploying the war file in Apache Tomcat server and tried to access the page, as posted by another user: https://stackoverflow.com/questions/47692024/deploy-django-on-tomcat – Harikrishnan K.N. Sep 06 '18 at 10:52
0

I don't see any configuration in your web.xml that actually specifies a WSGI callable object: one is required before an application be run.

See here for how to specify callables to modjy.

http://opensource.xhaus.com/projects/modjy/wiki/ModjyLocateCallables

Alternatively, compare your web.xml with the web.xml in the modjy demo web application.

https://fisheye3.atlassian.com/browse/jython/trunk/jython/Demo/modjy_webapp/WEB-INF/web.xml

Alan Kennedy
  • 131
  • 2