Skip to content

Feature idea resolve jars from maven repositories #900

Description

@Thrameos

One issue that people run when distributing Python packages with jars is that the jar file needs to become part of the Python module and be installed in the site packages. It is possible that we could add an alternative method such as
jpype.ivy.addArtifact("com.h2database:h2:1.4.200") which would automatically download the jar file and all dependencies and insert into the class path loader. It would depend on having Apache ivy already available in the class path.

Here is a prototype of the system.

from org.apache.ivy import Ivy
from org.apache.ivy.core import LogOptions
from org.apache.ivy.core.module.id import ModuleRevisionId
from org.apache.ivy.core.resolve import ResolveOptions
from org.apache.ivy.core.retrieve import RetrieveOptions
ivy = Ivy.newInstance()
ivy.configureDefault()
ro = ResolveOptions()
ro.setLog(LogOptions.LOG_QUIET)
ro.setConfs(["master"])
mri = ModuleRevisionId.newInstance("com.h2database","h2","1.4.200")
rr = ivy.resolve(mri, ro, True)
md = rr.getModuleDescriptor()
mRID = md.getModuleRevisionId()
destFolder = tempfile.gettempdir()
pattern = destFolder + "/[artifact]-[revision](-[classifier]).[ext]";
ro = RetrieveOptions()
ro.setConfs(["master"])
ro.setDestArtifactPattern(pattern);
ro.setLog(LogOptions.LOG_QUIET)
if ro.getDestArtifactPattern() is None:
    raise RuntimeError()
rr = ivy.retrieve(mRID, ro)
for file in rr.getRetrievedFiles():
    print(file.toPath())
    jpype.addClassPath(str(file.toPath().toString()))
jpype.JClass("org.h2.Driver")  # works now 

I know that scyjava uses a similar system for JGO. Is this a feature which people likely use? Does it belong in JPype?
@ctrueden any thoughts on this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions