Import packages installed from Maven central repo?
Hi,
Sorry for posting this question here but haven't found a proper mailing list or StackOverflow answers.
I want to reuse Java APIs installed with Maven from JPype.
Could you please advise a correct way on how to do that?
What I did:
- Created pom.xml with the necessary dependencies
- Launched mvn install to install all the dependencies to ~/.m2/repository and it seemed to work fine
Now I try to access any of the installed APIs, for example JPackage("com").xeiam.xchange.ExchangeFactory.INSTANCE.createExchange()
But it only asserts that the package is not callable, doesn't matter which class or method I try to trigger.
I tried to specify the class path to ~/.m2/repository during the JVM initialization with no luck.
And yes, I'm a Java noob :-)
What am I doing wrong?
Thank you!
Instead of adding ~/.m2/repository to your classpath, you need to add every single jar to the classpath. You can use this code to help you find them
def findJars(path):
for root, dir, files in os.walk(path):
for items in fnmatch.filter(files, "*.jar"):
yield os.path.join(root,items)
This will get you all jars below a certain path (for example, ~/.m2/repository), which you can then add to the jpype classpath. Obviously it would be smarter to just add the ones you actually need, but this should give you a quick and dirty way to get started.
You can also reuse some code from jip: from jip import cache_manager, pool, repos_manager from jip.maven import Artifact
artifact = Artifact.from_id(artifact_id) ### artifactid = 'groupid:artifactid:version'
cache_manager.get_jar_path(artifact, filepath=True)
Thank you very much! Got it working by copying Maven dependencies for the pom to a project subdir:
mvn org.apache.maven.plugins:maven-dependency-plugin:2.7:copy-dependencies
-f pom.xml
-DoutputDirectory=dependencies