From: Jeff A. <ja...@fa...> - 2018-09-30 17:51:18
|
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 > |