3

I want to update an old program from Java 8 to Java 15 with modules and therefore I rewrite and update a lot of code. Everything works fine until the update of the library to write spreadsheet documents.

In the old version, I used the org.odftoolkit with the simple-api with maven.

<dependency>
    <groupId>org.odftoolkit</groupId>
    <artifactId>odfdom-java</artifactId>
    <version>0.8.7</version>
</dependency>
<dependency>
    <groupId>org.odftoolkit</groupId>
    <artifactId>simple-java</artifactId>
    <version>0.4</version>
</dependency>

As described here, this API is deprecated and I want to step over to the current ODFDOM API. But the documentation is not current with the latest version and I did not found an example for the java module.

I added the maven dependencies, but the question is how to add this to the module-info.java file. All my attempts with

requires org.odftoolkit.odfdom.doc.table;

or equal ones have failed miserably.

My question may occur simply, but for me, it is a big mountain. What is the right way to do this? Thank you for any input.

Naman
  • 27,789
  • 26
  • 218
  • 353
ryanthara
  • 41
  • 6
  • *Edit*: I have removed one of the `requires` from the directive considering that was just a typo while posting this question. – Naman Jan 11 '21 at 07:53

1 Answers1

0

Derive the module name

jar --file=/path/to/your/jar/odfdom-java-0.8.7.jar --describe-module

Add the directive for dependency

In your case, if these dependencies are not yet modular or declare their Automatic-Module-Name. You can still make use of the derived name in the module directives to make use of the public classes within the packages of the modules.

requires odfdom.java;
requires simple.java;

As the specification of Module declaration guides:

requires {RequiresModifier} ModuleName ;

RequiresModifier:
(one of)
transitive static

you need to specify the module name instead of the packages that your code would rely upon.

Additionally, upon some research, I could find out, that you might want to test the BETA or RC version of the toolkit, as listed in the repository tags and maven central.

Naman
  • 27,789
  • 26
  • 218
  • 353
  • 1
    Thank you so much for your answer. I have rare time this week (snow is coming) and will take a look to it on the weekend. Likewise, I need to see if I wasn't using local jars with maven in the old version. To much time was gone so far... – ryanthara Jan 11 '21 at 18:09