使用 Django-Jython 和 Tomcat 进行部署?

发布于 2024-09-07 18:14:40 字数 2275 浏览 1 评论 0原文

我有一个 Django 应用程序,我们正在尝试使用 django-jython 部署到 Tomcat 服务器。

为了进行测试,我已成功为空 Django 应用程序创建了 WAR 存档文件。测试 Django 应用程序称为“chair”。

我们的 Tomcat 服务器显然不喜欢 WAR 档案文件,所以我分解(解压了这个),并将这些文件复制到服务器上。

网络服务器管理员为我创建了一个上下文,以及该上下文的目录(媒体跟踪)。

我已将 WAR 存档中的文件复制到该目录中,但我不太确定如何让该测试应用程序现在“运行”?

\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 

等等(我没有下降到比 chair/django/doj/Lib 目录更低的位置。)

上面的目录结构中是否有明显缺失的东西?

我到底如何让 Tomcat 服务器真正“运行”这个应用程序?如果您转到上下文目录,它不会自动运行(那里只有 application.py 和 application$py.class 文件,所以我不确定它会如何运行)。

我是否需要要求我的网络服务器管理员对 web.xml 文件执行某些操作?我检查了一下,里面似乎没有任何东西可以帮助这个应用程序运行:

<?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>

任何建议都将不胜感激 =)。

干杯, 胜利者

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奶气 2024-09-14 18:14:40

这是一个迟到的答案,但到目前为止我还没有看到这个问题。希望它仍然有帮助。
以下是我始终遵循的步骤(成功)。

1) 创建 war 文件:

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

context-root 的名称很重要,因为 Django-on-Jython 将操作您的 settings.py 文件并修改您的 MEDIA_URL 和 ADMINMEDIA_URL 以添加该上下文(例如 MEDIA_URL = '/chair/media/'),并且它必须与您在 Tomcat 中部署到的上下文相同。它将与生成的 war 文件同名(在本例中为 chair.war)。在外部 JAR 中至少包含 JDBC 驱动程序。

2)将战争部署到Tomcat(在我使用的任何Tomcat,版本5和5.5中从来没有出现过问题)。我通过 HTML 管理器应用程序手动执行此操作,网址为 http://server:8080/manager/html -它将需要身份验证,使用在 Tomcat 的 conf/users.xml 中具有管理员权限的用户名/密码(我是凭记忆写的)。有很多方法可以使用 Ant、Maven 或其他工具来自动化此操作,但手动也可以。

如果您绝对必须手动取消war文件,请使用与war文件(以及上下文根)完全相同的文件夹名称,在本例中是Tomcat安装文件夹中的webapps/chair。

3) 从 URL http://server:8080/chair/(加上任何其他 url 路径)访问已部署的应用程序(如 urls.py 中所定义)

Modjy servlet 是为您的 url 提供服务的运行程序,如以下定义所示:

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

如果您在 http://server:8080/chair/ 在 HTML 管理器中检查应用程序是否真正启动,并检查您的 Tomcat 日志是否有错误(通常是 tomcat 安装目录下的 logs/catalina.out) 。

官方文档中的更多信息: http://packages.python.org/django- jython/war-deployment.html

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

苍白女子 2024-09-14 18:14:40

我在 web.xml 中没有看到任何实际指定 WSGI 可调用对象的配置:在运行应用程序之前需要一个。

请参阅此处了解如何指定 modjy 的可调用项。

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

或者,将您的 web.xml 与 modjy 演示 Web 应用程序中的 web.xml 进行比较。

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文