feli
feli

Reputation: 3

how to import .py into java

I want to make a web application for books using java servlets with Tomcat. I want to import some code (that reads *.epub, *.pdf, *.doc, *.mobi, and *.txt files) from the project Calibre into my project, if it's possible.

Calibre source: http://bazaar.launchpad.net/~kovid/calibre/trunk/files Some source from this link I want to work into my project.

Application Calibre is an open source written in Python and C. What I want is to import sources written in python (.py), which allows me to read standard epub, pdf, txt ... in my project developed in java servlet to view and to convert the books. I using Eclipse(Java EE) and I do not know what steps to import these sources and how to make. It must to export these source to jar?

Upvotes: 0

Views: 422

Answers (3)

xuanji
xuanji

Reputation: 5097

Python and java are different languages. You cannot have java code call python code or the other way round without some sort of conversion. I think your best option is to either

  1. Look for a Java library that does what you want, or
  2. Write your website in python; there are many excellent libraries for these

Sure there are ways to call python from java, but it'll be rather hard to apply them to something as big Calibre, which also uses some C.

Upvotes: 0

glglgl
glglgl

Reputation: 91119

I see two other ways:

  1. You could work with Jython (but I have no experience with that and don't know if it solves your problem)

  2. You could write a JNI module for Java which in turn starts and uses the Python interpreter.

Upvotes: 0

James Black
James Black

Reputation: 41858

Python isn't compatible with Java, in that Java can't run python code.

But, there are a couple of options.

  1. Run the python code from your java app directly with a system call. I use ProcessBuilder for these situations, and you can look at http://javaevangelist.blogspot.com/2011/12/java-tip-of-day-using-processbuilder-to.html.
  2. Set up Calibre as a web application and call the conversion functions from your web application to the calibre webapplication you start up. It appears ready to run as a web application according to http://calibre-ebook.com/about and http://www.techrepublic.com/blog/opensource/how-to-use-calibre-to-access-your-ebook-collection-online/2275.

Upvotes: 1

Related Questions