Lin Ma
Lin Ma

Reputation: 10159

CPython 2.7 + Java

My major program is written in Python 2.7 (on Mac) and need to leverage some function which is written in a Java 1.8, I think CPython cannot import Java library directly (different than Jython)?

If there is no solution to call Java from CPython, could I integrate in this way -- wrap the Java function into a Java command line application, Python 2.7 call this Java application (e.g. using os.system) by passing command line parameter as inputs, and retrieve its console output?

regards, Lin

Upvotes: 0

Views: 230

Answers (2)

ndjensen
ndjensen

Reputation: 139

A number of open source projects have been written to enable calling Java from CPython, depending on your needs.

Upvotes: 0

Siva Arunachalam
Siva Arunachalam

Reputation: 7750

  • If you have lot of dependcieis on Java/JVM, you can consider using Jython.
  • If you would like to develop a scalable/maintainable application, consider using microservices and keep Java and Python components separate.
  • If your call to Java is simple and it is easy to capture the output and failure, you can go ahead with this running the system command to invoke Java parts.

Upvotes: 1

Related Questions