From: Ted L. F. <te...@pr...> - 2018-09-30 19:05:26
|
Hi, Jeff and Adam. Thanks for your replies. My goal is to see if I can produce a Java .class file using Jython, which can then be run using Java on the command line. A coworker was able to do this with Scala in less than 15 minutes (including installation), and I wanted to see if I could do the same thing with Jython. (I can run Jython itself with the script below just fine.) I'm still missing something, as I get the same error with either the CLASSPATH evironment variable or when explicitly setting it on the command line. For example: % ls HelloWorld.py HelloWorld$py.class % java HelloWorld$py -classpath /home/ted/jython2.7.0 Error: Could not find or load main class HelloWorld Any further suggestions are greatly appreciated. Thanks! Ted PS. In case it helps, here is some info on my environment: % jython --version Jython 2.7.0 % java -version openjdk version "1.8.0_171" OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-0ubuntu0.17.10.1-b11) OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode) % uname -srv Linux 4.13.0-46-generic #51-Ubuntu SMP Tue Jun 12 12:36:29 UTC 2018 Sent with [ProtonMail](https://protonmail.com) Secure Email. ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐ On Sunday, September 30, 2018 10:51 AM, Jeff Allen <ja...@fa...> wrote: > The normal way to use Jython would be like CPython: > > $ jython HelloWorld.py > > That's with an appropriate PATH, of course, or you say explicitly where the launcher is as part of the command. If you just wanted to run the the Python code, that would be the way. The compiled $py.class would only ever live in memory. > > But maybe you know this and have something more complicated in mind. You can run the class you made from a Java program (class with main()) that you write. But you could run the .py file from a Java program too, and I think more easily. Either way, you need the jython JAR on the path as Adam says. What do you have in mind that makes you want to compile it as a separate step like this? > > Jeff Allen > > On 29/09/2018 21:13, Ted Larson Freeman via Jython-users wrote: > >> I have just installed Jython 2.7, and am looking for a simple example of compiling a Python script down to a Java .class file. Following a suggestion on Stack Overflow, I tried to compile a file called HelloWorld.py, which contains this: >> >> class HelloWorld(object): >> def hello(self): >> print 'Hello, World!' >> >> if __name__ == '__main__': >> h = HelloWorld() >> h.hello() >> >> Using these Jython commands (in the same working directory): >> >> import py_compile >> py_compile.compile('HelloWorld.py') >> >> That produces a file called HelloWorld$py.class, but when I try to run it with java from the command line, I get this error: >> >> Error: Could not find or load main class HelloWorld >> >> Please let me know what commands I should use. >> >> Thanks. >> >> Ted |