3

I have an application which runs in a sandbox environment using an OpenJDK. The JDK directory has a jmods folder.

The documentation regarding jmods isn't that great. From what I understand, jmods is useful if I want to create another custom JRE using JLink.

Say, if I don't want to do that and just want to have a JDK which can build and run my Java SWT application. Will it be safe to simply remove the jmods directory?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • Why do you want to delete the jmods directory? One thing you can do, is to create a test that performs all of the tasks you want, then delete the directory and see what happens. Personally, I don't think the folder is specific to jlink. You can build and run apps using a modular structure, in which case you would need the jmods folder and the jmod file. – matt Jul 21 '22 at 12:35
  • @matt I am currently on the process of notarizing our MacOS application which has am embedded JDK. This process involves code signing all dylib files. Unfortunately apple is flagging all the dylib files which are inside the .jmod packages in the JDK since they are not signed with apple's certificate . While I am trying to find a way to resolve it, I have seen people completely remove the folder (during notarization), but I am not sure if that's a case to case basis or not. While we are exploring all options, simply removing all jmods makes my job easier, but it has to be the right decision. – Tanmay Majumdar Jul 21 '22 at 16:39
  • I am not sure how much you have done to prepare a JDK to distribute with your application, did you try creating one with jlink? – matt Jul 22 '22 at 07:32

1 Answers1

2

Does the jmods directory in jdk/jmods have any role during application runtime?

No. These are only archives that are used as input to jlink. The class files and other resources that are used during runtime are stored in the lib/modules archive, which is in a custom format that can be read for instance with the jimage tool. (or by JDK code using one of two jimage library implementations in the JDK)

.jmod files are not meant to be used during execution. If you try to put a .jmod file on the module path, you even get an error:

java.lang.module.FindException: JMOD format not supported at execution time: <some.mod>.jmod

Say, if I don't want to do that and just want to have a JDK which can build and run my Java SWT application. Will it be safe to simply remove the jmods directory?

If you use jlink to create a runtime image, it will not contain a jmods directory in the first place. So, there's nothing you should have to remove.

Jorn Vernee
  • 31,735
  • 4
  • 76
  • 93
  • 1
    @matt `.jmod`s are not libraries. They are really only archives meant to be used as inputs to `jlink`. You can't put a `.jmod` on the class path or module path to have the runtime load classes from them. Though, you could theoretically extract files from a `.jmod` (since it's essentially a zip file) and then use those files. (just like you are able to extract a `.jar` file and use the files). – Jorn Vernee Jul 21 '22 at 12:38
  • If you try to put a `.jmod` file on the module path, you even get an error: `java.lang.module.FindException: JMOD format not supported at execution time: .jmod` – Jorn Vernee Jul 21 '22 at 12:51
  • Okay, after reviewing the [openjfx](https://openjfx.io/) documentation a little. It looks like you need the lib/sdk to build and run the application and you also need the jmod's to build a runtime image. It's been awhile, but I though I was able to build and run with just the jmods. That seems to be wrong. – matt Jul 21 '22 at 13:33
  • @JornVernee Your answer has helped a lot and sort of confirms my assumption. _Say, if I don't want to do that and just want to have a JDK which can build and run my Java SWT application. Will it be safe to simply remove the jmods directory_ I think, a slight clarification from my end is required here. What I meant is - is it safe to simply remove the jmods directory from the ready made JDKs (not the one generated using Jlink), This is when I only intent to use the JDK to run my application. – Tanmay Majumdar Jul 21 '22 at 16:54
  • @TanmayMajumdar I would recommend against tampering with the JDK. Much safer to just run jlink to create a runtime image. If you care about size, that will also allow you to strip other kinds of unneeded things for the runtime image. – Jorn Vernee Jul 21 '22 at 17:31