I am trying to import a Java API, which is distributed as a jar file. I followed the instructions from this answer at a similar question in Stack Overflow, but it didn't work.
In Jython, I did:
>>> import sys
>>> sys.path.append("/path/to/jar/api")
>>> from com.thingmagic import *
Traceback (most recent calls last):
File "<stdin>", line 1, in <module>
ImportError: no module named thingmagic
Am I missing something or did I do something wrong?
You can do the easy_install for jython. Then next time you startup jython you will be able to import it. The official docs are here: jython.org/jythonbook/en/1.0/…
register 'script.py' using jython as script_udf; a = LOAD 'data. json' USING PigStorage('*') as (line:chararray); teams = FOREACH a GENERATE script_udf.
An API is an Application Programming Interface, so it defines the methods you can use. ( wikipedia link) A JAR is a Java Archive, it is just a packaged Java Application. ( wikipedia link)
You need to provide the full path of the JAR file. Change
sys.path.append("/path/to/jar/api")
to
sys.path.append("/path/to/jar/api/whatever_the_name_is.jar")
The problem was that I was using only one backslash on the path (I'm developing on Windows), instead of two:
sys.path.append("C:\\remember\\to\\use\\two\\backaslashes\\jarName.jar")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With