了解如何使用Jython的问题 [英] Issues understanding how to use Jython

查看:114
本文介绍了了解如何使用Jython的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习Jython,并且在实现方面遇到了一些问题.我浏览了Jython 2.5随附的Demo文件,但仍不确定如何实现Jython来获得所需的文件.

I've just started learning Jython, and I'm having some issues with implementation. I've looked through the Demo files that come with Jython 2.5, and I'm still unsure how to implement Jython to get what I want.

当前,我有Java代码将Python服务器作为进程执行. Python服务器又将Java代码的第二部分作为子进程启动.我本来打算用Java NIO服务器替换Python服务器,但是这没有让我感到悲伤,因此,为什么我要尝试Jython.我也想将所有这些都放入.jar.

Currently, I've got Java code executing a Python server as a Process. The Python server in turn starts a second section of Java code as a subprocess. I was originally going to replace the Python server with a Java NIO server, but that's given me no end of grief, and thus why I'm trying Jython. I also want to get all of this into a .jar.

我尝试制作一个简单的Python文件(print "Hello World").它与Jython一起运行,但是当我尝试使用java(在执行jython -m compileall之后)运行它时,它说找不到main.我认为我需要在Python代码中添加一些内容才能使其正常工作,但是我不确定是什么.

I tried making a simple Python file (print "Hello World"). It runs with Jython, but when I try to run it using java (after doing jython -m compileall.) it says that it can't find main. I assume that I need to add something to my Python code to make it work, but I'm not sure what.

我要得到的确切错误是-

The exact error I'm getting is this-

Exception in thread "main" java.lang.NoClassDefFoundError: jythonTest
Caused by: java.lang.ClassNotFoundException: jythonTest
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: jythonTest.  Program will exit.

推荐答案

我认为答案是CLASSPATH.

I think the answer is CLASSPATH.

print "Hello"

让我们运行它

> python hello.py
Hello

> jython hello.py
Hello

编译(我使用py_compile编译单个文件)

Compile (I used py_compile to compile single file)

> jython -m py_compile hello.py

运行java

> java -classpath d:\P\jython253\jython.jar;. hello$py
Hello

注意类路径中的点. Java必须在当前目录中找到已编译的类.

Note the dot in classpath. It is required for java to find your compiled class in current directory.

这篇关于了解如何使用Jython的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆