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)
- Create a new Maven project via Maven Archetype (javafx-archetype-simple) and follow OpenJfX tutorial for non modular maven project in Netbeans
- 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>
- 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();
}
- 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);
}
}
Now clean and build and run the project. The described error should occur.
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.
- 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 ;-)