• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

使用Jython的问题

用户头像
it1352
帮助1

问题说明

我刚刚开始学习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.

正确答案

#1

我认为答案是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.

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfkbbb
系列文章
更多 icon
同类精品
更多 icon
继续加载