Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage without JDK #699

Open
ennioVisco opened this issue Nov 18, 2023 · 6 comments
Open

Usage without JDK #699

ennioVisco opened this issue Nov 18, 2023 · 6 comments

Comments

@ennioVisco
Copy link

ennioVisco commented Nov 18, 2023

Hello,

I cannot find docs/other issues on this topic, so I considered using a new issue.

In recent versions of Java, tools likeJava modules and jlink made it extremely easily to build tailor-made JREs that select only the parts of the JDK that are used by the target Java library.

I was thinking that it would be really cool if there was a way to use that JRE, to avoiding completely the extra step for the user of installing and switching to the appropriate version of the JDK.

Why is this not possibile? Are there known challenges in that?

@cmacdonald
Copy link
Contributor

I had some thoughts about this.

  1. Pyjnius allows access to all of Java, so limiting to particular modules probably precludes.

  2. IMO, any packaging of minimal Java for a particular Python application that use jnius seems out of scope for the Pyjnius project itself.

  3. The JDK is definitely needed for building Pyjnius. I haven't thought about the choice of JRE/JDK for using Pyjnius - but I have a feeling for the JDK is needed.

@ennioVisco
Copy link
Author

ennioVisco commented Nov 23, 2023

I had some thoughts about this.

Thanks for the nice comments, let me share my thoughts and ideas about it:

My comments on your nice thoughts

  1. Pyjnius allows access to all of Java, so limiting to particular modules probably precludes.

I definitely agree with this, I don't think Pyjnius should be limited in this sense.

  1. IMO, any packaging of minimal Java for a particular Python application that use jnius seems out of scope for the Pyjnius project itself.

I also agree with this, I don't believe necessarily that Pyjnius should be concerned by packaging, in my view, the ideal setting would just be to allow the user of Pyjnius to select a JRE that is different from the one at JAVA_HOME!

  1. The JDK is definitely needed for building Pyjnius. I haven't thought about the choice of JRE/JDK for using Pyjnius - but I have a feeling for the JDK is needed.

I'm sorry, I confess my lacks in understanding how Pyjnius works. While I think it makes perfect sense that the full JDK is needed when building, at the same time I would expect Pyjnius's runtime requirements from the jdk to be some subset of the JDK, and, specifically, the union between the set of JDK modules needed by the running application + some set of extra JDK modules required by Pyjnius itself (say, e.g. the Reflection API).
I would consider reasonable to include these dependencies at build time in Java, and therefore an ad-hoc runtime should work without any issues.

The use case I have in mind

My use case is pretty simple, I want to deliver a python package installable from pip (just like pyjnius), and I want to provide the right JRE to run the package so that:

  • the user doesn't need to install another external software (in this case the JDK)
  • the user might have a different JDK version in the running enviroments (because she is an active Java developer)
  • the user might want to use the output of my package as input to some other package using Pyjnius and that requires a different version of the JDK (in which case she'd have to manually play with the env variables to make this work)

Are these comments helpful on the topic? Please let me know if they are not :)

@cmacdonald
Copy link
Contributor

cmacdonald commented Nov 23, 2023

OpenJDK is available in Conda. Why not specify conda, and then not have to be bothered with repackaging openjdk for pip.

I'm sorry, I confess my lacks in understanding how Pyjnius works. While I think it makes perfect sense that the full JDK is needed when building, at the same time I would expect Pyjnius's runtime requirements from the jdk to be some subset of the JDK, and, specifically, the union between the set of JDK modules needed by the running application + some set of extra JDK modules required by Pyjnius itself (say, e.g. the Reflection API).

I widely agree with whats written here. We can investigate further (could you try to switch JAVA_HOME to a JRE and see if jnius continues to work).

@ennioVisco
Copy link
Author

ennioVisco commented Dec 7, 2023

OpenJDK is available in Conda. Why not specify conda, and then not have to be bothered with repackaging openjdk for pip.

I'm sorry, I confess my lacks in understanding how Pyjnius works. While I think it makes perfect sense that the full JDK is needed when building, at the same time I would expect Pyjnius's runtime requirements from the jdk to be some subset of the JDK, and, specifically, the union between the set of JDK modules needed by the running application + some set of extra JDK modules required by Pyjnius itself (say, e.g. the Reflection API).

I widely agree with whats written here. We can investigate further (could you try to switch JAVA_HOME to a JRE and see if jnius continues to work).

Hello there, sorry for the late reply.
From a preliminary test it seems to be working by switching the JAVA_HOME to the path of the custom JRE.
I will need to make more complete tests (I'm now using the same machine, and it could be it somehow still detects JDK stuff), but in principle this seems to confirm that it can work :)

@cmacdonald
Copy link
Contributor

Thanks for the report. Probably some GitHub actions could be made that test this too.

@cmacdonald
Copy link
Contributor

Testing confirms jnius works with only a JRE - see #705.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants