0

I am in the process of converting a working java 8 project to java 11. I don't want to use module yet (I know there are some advantages, but so far I just want the project to run under java 11). So there is no module-info.java in the project src folder.

I use Netbeans 11, and the (Maven based) project can be successfully built (with openjdk 11 under Linux). However when I run it, I get

Error occurred during initialization of boot layer java.lang.module.FindException: Unable to derive module descriptor for /home/helloWorld/.m2/repository/org/apache/tika/tika-parsers/1.21/tika-parsers-1.21.jar Caused by: java.lang.module.InvalidModuleDescriptorException: Provider class org.apache.tika.parser.external.CompositeExternalParser not in module

My classes are all in packages so this answer does not fit, and neither does this other one.

The project pom.xml is as follows :

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MRE</groupId>
<artifactId>Example</artifactId>
<version>1.0.12</version>
<packaging>jar</packaging>

<parent>
    <artifactId>MREWeb</artifactId>
    <groupId>MRE</groupId>
    <version>1.0-SNAPSHOT</version>
</parent>

<dependencies>
    <dependency>            
        <groupId>MRE</groupId>
        <artifactId>Base</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>org.apache.tika</groupId>
        <artifactId>tika-parsers</artifactId>
        <version>1.21</version>
        <type>jar</type>
    </dependency>        

    <dependency>
        <groupId>org.apache.opennlp</groupId>
        <artifactId>opennlp-tools</artifactId>
        <version>1.9.0</version>
    </dependency>

    <dependency>
        <groupId>net.sourceforge</groupId>
        <artifactId>prajna</artifactId>
        <version>1.0</version>
    </dependency>

    <dependency>
        <groupId>com.github.stefanbirkner</groupId>
        <artifactId>system-rules</artifactId>
        <version>1.19.0</version>
        <scope>test</scope>
    </dependency>        

    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>11.0.2</version>
        <type>jar</type>
    </dependency>

    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>11.0.2</version>
    </dependency>        

<build>

    <resources>
        <resource>
            <!--We specify the resource folder that should be included-->
            <directory>src/main/resources</directory>              
        </resource>
    </resources>

    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-enforcer-plugin</artifactId>
            <version>3.0.0-M2</version>
            <executions>
                <execution>
                    <id>enforce-maven</id>
                    <goals>
                        <goal>enforce</goal>
                    </goals>
                    <configuration>
                        <rules>
                            <requireMavenVersion>
                                <version>3.3.9</version>
                            </requireMavenVersion>
                        </rules>    
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <!--See here for details https://www.baeldung.com/executable-jar-with-maven-->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>
                                    ${mainClass}
                                </mainClass>                                    
                            </manifest>
                            <!--Adds custom entry for version to manifest and changes Built By value-->
                            <manifestEntries>
                                <!--We use implementation version so that it can be retrieved within java from package methods-->
                                <Implementation-Version>${project.version}</Implementation-Version>
                                <Implementation-Title>${project.artifactId}</Implementation-Title>
                                <Built-By>HelloWorld</Built-By>
                            </manifestEntries>
                        </archive>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>0.0.2</version>
            <configuration>
                <mainClass>${mainClass}</mainClass>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <release>11</release>                    
            </configuration>
        </plugin>           

    </plugins>

</build>

<name>MREWeb_Example</name>
</project>

The command line that Netbeans output in its console is :

cd /home/helloWorld/java/projects/example; JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 /home/helloworld/netbeans/java/maven/bin/mvn "-Dexec.args=-classpath %classpath mre.example.MainApp" -Dexec.executable=/usr/lib/jvm/java-11-openjdk-amd64/bin/java -DskipTests=true clean javafx:run

How can I put the CompositeExternalParser class in the module (which module indeed) ?

Edit (after adding javafx to the module-path and add-modules as advised in comments)

If I run the compiled (fat) jar from the command line via java --module-path /home/helloworld/Java/JavaFx/javafx-sdk-11.0.2/lib --add-modules javafx.controls,javafx.fxml -jar example-jar-with-dependencies.jar the app runs fine. So there rather be something to do rather in Netbeans, right (but what ;-) )?

Minimal Reproducible Example (as requested in the comments)

  1. Create a new Maven project via Maven Archetype (javafx-archetype-simple) and follow OpenJfX tutorial for non modular maven project in Netbeans
  2. Add Tika parser dependency in pom.xml
  <dependency>
        <groupId>org.apache.tika</groupId>
        <artifactId>tika-parsers</artifactId>
        <version>1.21</version>
        <type>jar</type>
   </dependency>

The pom.xml becomes

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>minimum.reproducible</groupId>
    <artifactId>MavenExample</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>11.0.2</version>
        </dependency>
                <dependency>
            <groupId>org.apache.tika</groupId>
            <artifactId>tika-parsers</artifactId>
            <version>1.21</version>
            <type>jar</type>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.2</version>
                 <configuration>
                       <mainClass>minimum.reproducible.mavenexample.App</mainClass>
                 </configuration>
             </plugin>
 <!--To include the main class attribute in the manifest file-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.1.1</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>minimum.reproducible.mavenexample.App</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
         </plugins>
     </build>
 </project>
  1. Add this method from Tika example
public String parseExample() throws IOException, SAXException, TikaException {
    AutoDetectParser parser = new AutoDetectParser();
    BodyContentHandler handler = new BodyContentHandler();
    Metadata metadata = new Metadata();
    try (InputStream stream = new FileInputStream(new File("/home/helloWorld/Texts/test.txt"))) {
        parser.parse(stream, handler, metadata);
        return handler.toString();
    }
  1. Augment the start method with some code to run the previously created method
    public void start(Stage stage) {
        var javaVersion = SystemInfo.javaVersion();
        var javafxVersion = SystemInfo.javafxVersion();

        var label = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + ".");
        var scene = new Scene(new StackPane(label), 640, 480);
        stage.setScene(scene);
        stage.show();

        System.err.println("Starting tika parsing");
        try {
            String result = parseExample();
            System.err.println("The parsing yielded : ");
            System.err.println(result);

        } catch (IOException | SAXException | TikaException ex) {
            Logger.getLogger(App.class.getName()).log(Level.SEVERE,
                    null,
                    ex);
        }
    }
  1. Now clean and build and run the project. The described error should occur.

  2. Please note : If this minimal reproducible example program is launched from the command line without Tika in Pom and the Tika related stuff in App.java the program runs fine.

java --module-path /home/helloworld/Java/JavaFx/javafx-sdk-11.0.2/lib --add-modules javafx.controls,javafx.fxml -jar MavenExample-1.0-SNAPSHOT.jar

However if I try to run it from the command line again but with all Tika stuff as described in the minimal reproducible example above, I get

Missing JavaFX application class minimum.reproducible.mavenexample.App

although Netbeans 11 keeps showing the java.lang.module.InvalidModuleDescriptorException mentioned above.

  1. Yet if the following lines are added to the pom.xml
<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.6.0</version>
                <configuration>
                    <mainClass>minimum.reproducible.mavenexample.App</mainClass>
                </configuration>
            </plugin>

Now the project can be run via mvn exec:java. So I guess that the issue is coming from the javafx-maven-plugin, isn't it ?

Any help appreciated ;-)

HelloWorld
  • 2,275
  • 18
  • 29
  • Make sure you put Apache Tika on your *classpath* and not on your *modulepath* , since it isn't a module? – Gagravarr Jun 05 '19 at 06:14
  • Thanks @Gagravarr. But the project is using Maven, so Maven should manage the classpath, shouldn't it ? – HelloWorld Jun 05 '19 at 07:21
  • 1
    Can you provide a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example)? – ZhekaKozlov Jun 05 '19 at 08:12
  • By default, Maven only manages your compile-time classpath. It can also package stuff up for runtime, but only with extra options, and you haven't detailed what (if any) of those you are using! – Gagravarr Jun 05 '19 at 08:22
  • @Gagravarr I added the complete pom.xml. Please see my edit. – HelloWorld Jun 05 '19 at 08:58
  • Is there any way to get the command line to be printed out? The error is only possible if tika-parsers-1.21.jar has been deployed on the module path. – Alan Bateman Jun 05 '19 at 12:28
  • @AlanBateman see my edit where I added the command line output by Netbeans in its console. – HelloWorld Jun 05 '19 at 12:52
  • The command line that you pasted in is `mvn` command, I'm trying to see the command that is running `java` with the module path set. For your "Edit 1" command then you are missing the module path and --add-modules options needed to locate and resolve the JavaFX modules. – Alan Bateman Jun 05 '19 at 14:27
  • @ZhekaKozlov a minimal reproducible example has been added. Please see my last edit. – HelloWorld Jun 06 '19 at 13:35
  • @AlanBateman the command to get the same error as in the IDE is : `java --module-path /home/helloWorld/Java/JavaFx/javafx-sdk-11.0.2/lib:/home/helloWorld/.m2/repository/org/apache/tika/tika-parsers/1.21 --add-modules ALL-MODULE-PATH -jar MavenExample-1.0-SNAPSHOT.jar` – HelloWorld Jun 07 '19 at 03:25
  • That explains it. tika-parsers-1.21.jar needs to be on the class path, not the module path. If you change the command line to `java --module-path javafx-sdk-11.0.2/lib --class-path MavenExample-1.0-SNAPSHOT.jar:/tika-parsers-1.21.jar mre.example.MainApp` then I assume you will get further. Someone more expert at Maven may be able to get it to do the right thing. – Alan Bateman Jun 07 '19 at 09:43

0 Answers0