Re: Import Python class from Java
Jim Baker <[email protected]>
| Newsgroups | gmane.comp.lang.jython.user |
|---|---|
| Message-ID | <CAOhO=aMbhmy8ZsJ6B6bQNEaRA7k5i6CkSn3q0vDWu+64Hz7c8w@mail.gmail.com> |
Julian, That's probably me in the video you mention (so likely https://www.youtube.com/watch?v=hLm3garVQFo) In that video, I was referencing the Clamp project, which builds on new functionality in Jython 2.7 such that we can *precisely* generate the Java bytecode produced for Python classes that implement Java interfaces and/or extend a Java class. By doing this precise generation, we can ensure aspects like Java serializability, construction, and the specific naming, so that you can import and use in Java (or other JVM languages). So this means you would have to modify your class A such that it does the requisite implementation/extension. In turn, this implementation/extension allows Java code to import and use your Python class - it knows how to call your code. Clamp is demoed here, https://github.com/jimbaker/clamped, and is under sporadic development at https://github.com/jythontools/clamp There are other things to be done, but I see two major missing features: - Java annotations. Python classes should be able to support Java annotations on classes and methods, ideally use @-notation - so treating Java annotations as if they are Python decorators. This is just an extension of the precise bytecode generation I mentioned. - Maven jars. Clamp currently supports using sys.path for loading jars, via a jar.pth file in site-packages. (See https://docs.python.org/2/library/site.html on .pth file processing.) Clamp should be able to resolve Maven coordinates, as specified in your package's setup.py, to get jar artifacts, install in site-packages, and thereby place on sys.path. No more telling people, you need to put x.y.z.jar on CLASSPATH. In my experience, Clamp works well enough, except when building jars on Windows, but it needs unit testing and refactoring. (The existing Clamp codebase is a good example of a prototype to try out ideas that proved to be too successful.) The metaclass approach we use, as inspired by SqlAlchemy, has shown itself to be a nice API and we will certainly keep. Other aspects are still subject to change, but I suspect any changes will be minor at most for users. - Jim On Thu, Sep 10, 2015 at 6:37 AM, Julian Kennedy <[email protected]> wrote: > Hi Guys > > I somehow remember seeing a recent video showing directly importing a > python class from java. Something along the lines of: > > import some.python.module.MyClass > > class A { > // Some java code > > MyClass a = new MyClass(); > > // More java code > } > > Is this correct? Or did I see wrong? > > Regards > > > ------------------------------------------------------------------------------ > Monitor Your Dynamic Infrastructure at Any Scale With Datadog! > Get real-time metrics from all of your servers, apps and tools > in one place. > SourceForge users - Click here to start your Free Trial of Datadog now! > http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140 > _______________________________________________ > Jython-users mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/jython-users > > ------------------------------------------------------------------------------ Monitor Your Dynamic Infrastructure at Any Scale With Datadog! Get real-time metrics from all of your servers, apps and tools in one place. SourceForge users - Click here to start your Free Trial of Datadog now! http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140 _______________________________________________ Jython-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jython-users