使用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.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfkbbb
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20