Java FX Modular Application, Module not found (Java 17, Intellij) - java

Hello I have a problem with my modular Java FX Application.
First of all I created a JavaFX Project with the Intellij Wizard.
I added the Java FX lib:enter image description here
I also added the VM options:enter image description here
But I always get this errormessage:enter image description here
"Error occurred during initialization of boot layer
java.lang.module.FindException: Module com.example.hudrava_test not found
"
Thank you.

Steps to address your issue
Ensure that you are using the most recent stable version of Idea (currently 2021.3.2), Java and JavaFX (currently 17.0.2).
Discard your current project.
Create a new project.
Follow the instructions at Create a new JavaFX project provided by Idea on how to use their wizard.
If you follow the instructions exactly it should work.
You don't need to add "the Java FX lib" to the project manually.
The wizard will create a dependency in Maven or Gradle which includes the most common JavaFX modules.
You don't need to download or use the JavaFX SDK mentioned at openjfx.io.
You don't need to explicitly set any VM arguments such as --add-modules the wizard will create the a module-info.java file which references the modules.
Before proceeding any further, make sure that the basic generated project build and runs in your environment (according to the build and execution instructions documented by IntelliJ for the new JavaFX project wizard).
Using additional JavaFX modules
If you want to use additional JavaFX modules (e.g. javafx.media or javafx.web):
Add the additional modules manually to the maven or gradle build file.
Reimport the build file into the Idea project.
Add requires clauses form the modules to the module-info.java.
Making your application non-modular
Even if your application is made non-modular, you still need to have JavaFX modules on the module path as that is the only way the execution of JavaFX is supported.
If you don't want a modular application, you can delete the module-info.java file and manually add VM arguments for the module path to the JavaFX and an --add-modules switch.
I do not advise doing this step unless:
You have a good reason not to have a non-modular application (e.g. rely on 3rd party dependencies which do not integrate easily with the Java module system), AND
You have knowledge about how to make non-modular JavaFX applications.
Cause of the module find exception
The reason for your specific error:
java.lang.module.FindException: Module com.example.hudrava_test not found
is because you don't have module-info.java for a module with that name on the module path. Note that is not a JavaFX module name, but something you have specified. You have tried to run the application by specifying a class name within the non-existent module, e.g.
java --module-path <somepath> -m com.example.hudrava_test/com.example.hudrava_test.HelloApplication
You can find out further info about that in:
java.lang.module.FindException: Module not found.
However, you should not need to manually take the steps outlined in that answer, because, when you create a new project using the new JavaFX wizard, it will automatically create a module-info.java file and place your application's build output on the modulepath.
So the error was caused by something you did after creating the project with the wizard (I don't know what). When you create a new project, you should not have the error.
On module naming and underscores
The Jenkov module tutorial states:
A Java module name follows the same naming rules as Java packages. However, you should not use underscores (_) in module names (or package names, class names, method names, variable names etc.) from Java 9 and forward, because Java wants to use underscore as a reserved identifier in the future.
It is recommended to name a Java module the same as the name of the root Java package contained in the module - if that is possible (some modules might contain multiple root packages).
So, it is inadvisable to have underscores in either your module or your package name.
More info on module naming suggestions is provided in:
How should I name my Java 9 module?

Related

Unable to launch a JavaFX application which uses Apache POI

I have a JavaFX application that works as expected. I need to use Apache POI to read and write excel files. The following are the steps I have taken:
Added the required dependency
implementation 'org.apache.poi:poi-ooxml:5.2.3'
Added the module to module-info.java
requires org.apache.poi.ooxml;
Tried to use the library within a function:
#FXML
private void downloadTemplate() {
XSSFWorkbook workbook = new XSSFWorkbook();
}
All this is fine with no issues. However when I try to run the application, I get the following two errors (interchanging)
> Task :Start.main() FAILED
Error occurred during initialization of boot layer
java.lang.module.FindException: Module SparseBitSet not found, required by org.apache.poi.ooxml
and
> Task :Start.main() FAILED
Error occurred during initialization of boot layer
java.lang.module.FindException: Module commons.math3 not found, required by org.apache.poi.ooxml
I can however, clearly see both libraries under 'external libraries'
I am using IntelliJ Community Edition 2022.1.2 and running the project using Java 17.0.1. Any help would be highly appreciated.
SparseBitSet is an automatic module, it has no module-info of its own (probably commons-math3 is as well), and is without an Automatic-Module-Name entry in its manifest.
Gradle puts libraries without a module-info.class or an Automatic-Module-Name in their manifest on the class path, not the module path, so they won't be treated as modules, and the module finder won't find them.
You can:
hack the gradle build to allow the modules to be found. (I don't use Gradle so I have no specific advice on how to do that other than referring to the documentation).
Hack the library jar which you want to be treated as a module to include a module-info.class or an Automatic-Module-Name in its manifest.
Or, switch to maven, which automatically places automatic modules on the module path.
The easiest way to do this, IMO, is to create a new JavaFX project in Idea, then add the required dependencies as maven dependencies and add your code.
Or, as swpalmer suggests in the comments, request that library maintainers update their codebase to make their libraries modular.
And, when you run your app, make sure all jars are on the module path, not the class path.
Or, make your app non-modular by removing the module-info.java from it, then manually place the JavaFX modules on the module-path and add them with the --add-modules switch.
FAQ
Are you SURE that automatic modules are put on the class path by Gradle?
From the Gradle documentation section Building Modules for the Java Module System:
To tell the Java compiler that a Jar is a module, as opposed to a
traditional Java library, Gradle needs to place it on the so called
module path. It is an alternative to the classpath, which is the
traditional way to tell the compiler about compiled dependencies.
Gradle will automatically put a Jar of your dependencies on the module
path, instead of the classpath, if these three things are true:
java.modularity.inferModulePath is not turned off
We are actually building a module (as opposed to a traditional
library) which we expressed by adding the module-info.java file.
(Another option is to add the Automatic-Module-Name Jar manifest
attribute as described further down.)
The Jar our module depends on is itself a module, which Gradles
decides based on the presence of a module-info.class — the compiled
version of the module descriptor — in the Jar. (Or, alternatively, the
presence of an Automatic-Module-Name attribute the Jar manifest)
It is the third point that is key. Java can treat a library with no module-info.class and no Automatic-Module-Name in the Jar manifest as an automatic module if it is on the module path. However, Gradle will by default, only place libraries which fulfill one of those two conditions on the module path.
Using jewelsea's answer above, I have been able to solve the problem. I am posting the answer here to help anyone else who encounters the problem in future.
So, the overall problem is, as said in the answer above, both SparseBitSet and commons-math3 are automatic modules with no module-info of their own. The solution that worked for me was to convert them into the modules expected by the project. Here are the steps I took:
Use a gradle plugin 'extra-java-module-info'. The github page didn't show how to import it to a normal gradle file so here it is:
plugins {
id 'org.gradlex.extra-java-module-info' version '1.0'
}
Note the names that your application expects for the modules. In my case, from the error messages thrown, they were 'SparseBitSet' and 'commons-math3'
Locate the said libraries on the sidebar under 'external libraries' and note the 'jar' file names. In my case, they were 'commons-math3-3.6.1.jar' and 'SparseBitSet-1.2.jar'.
Add a section 'extraJavaModuleInfo' to your gradle files and use the parameters as follows: module('jar file name', 'name expected by your project', 'jar version'), as shown in the blue rectangle in the image above.
extraJavaModuleInfo {
module('commons-math3-3.6.1.jar', 'commons.math3', '3.6.1')
module('SparseBitSet-1.2.jar', 'SparseBitSet', '1.2')
}
That's it. Try to sync and run your project. Thanks jewelsea.

Error occurred during initialization of boot layer java.lang.module.FindException: Module javafx.base not found [duplicate]

I'm having trouble getting IntellJ to recognize JavaFX packages. With a new JavaFX project, with OpenJDK 11, when trying to build the project, IntelliJ can't recognize the JavaFX packages.
I've imported openjfx:javafx-base-11 from the Maven repo.
I've looked at other questions and the solutions seem to range from checking that the bytecode is at the right level (mine is), and that the project language is correct (mine is).
Anyone have any ideas?
Edit:
Error:
As mentioned in the comments, the Starting Guide is the place to start with Java 11 and JavaFX 11.
The key to work as you did before Java 11 is to understand that:
JavaFX 11 is not part of the JDK anymore
You can get it in different flavors, either as an SDK or as
regular dependencies (maven/gradle).
You will need to include it to the module path of your project, even if your project is not modular.
JavaFX project
If you create a regular JavaFX default project in IntelliJ (without Maven or Gradle) I'd suggest you download the SDK from here. Note that there are jmods as well, but for a non modular project the SDK is preferred.
These are the easy steps to run the default project:
Create a JavaFX project
Set JDK 11 (point to your local Java 11 version)
Add the JavaFX 11 SDK as a library. The URL could be something like /Users/<user>/Downloads/javafx-sdk-11/lib/. Once you do this you will notice that the JavaFX classes are now recognized in the editor.
Before you run the default project, you just need to add these to the VM options:
--module-path /Users/<user>/Downloads/javafx-sdk-11/lib --add-modules=javafx.controls,javafx.fxml
Run
Maven
If you use Maven to build your project, follow these steps:
Create a Maven project with JavaFX archetype
Set JDK 11 (point to your local Java 11 version)
Add the JavaFX 11 dependencies.
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11</version>
</dependency>
</dependencies>
Once you do this you will notice that the JavaFX classes are now recognized in the editor.
You will notice that Maven manages the required dependencies for you: it will add javafx.base and javafx.graphics for javafx.controls, but most important, it will add the required classifier based on your platform. In my case, Mac.
This is why your jars org.openjfx:javafx-controls:11 are empty, because there are three possible classifiers (windows, linux and mac platforms), that contain all the classes and the native implementation.
In case you still want to go to your .m2 repo and take the dependencies from there manually, make sure you pick the right one (for instance .m2/repository/org/openjfx/javafx-controls/11/javafx-controls-11-mac.jar)
Replace default maven plugins with those from here.
Run mvn compile javafx:run, and it should work.
Similar works as well for Gradle projects, as explained in detail here.
EDIT
The mentioned Getting Started guide contains updated documentation and sample projects for IntelliJ:
JavaFX 11 without Maven/Gradle, see non-modular sample or modular sample projects.
JavaFX 11 with Maven, see non-modular sample or modular sample projects.
JavaFX 11 with Gradle, see non-modular sample or modular sample projects.
The issue that JavaFX is no longer part of JDK 11.
The following solution works using IntelliJ (haven't tried it with NetBeans):
Add JavaFX Global Library as a dependency:
Settings -> Project Structure -> Module. In module go to the
Dependencies tab, and click the add "+" sign -> Library -> Java->
choose JavaFX from the list and click Add Selected, then Apply settings.
Right click source file (src) in your JavaFX project, and create a new
module-info.java file. Inside the file write the following code :
module YourProjectName {
requires javafx.fxml;
requires javafx.controls;
requires javafx.graphics;
opens sample;
}
These 2 steps will solve all your issues with JavaFX, I assure you.
Reference : There's a You Tube tutorial made by The Learn Programming channel, will explain all the details above in just 5 minutes. I also recommend watching it to solve your problem:
https://www.youtube.com/watch?v=WtOgoomDewo
Update Dec 14, 2020
Intellij has created a new JavaFX project wizard for Idea.
I highly recommend that, if you have an issue getting a JavaFX project to work, then use the new JavaFX project wizard to:
Create a new project using the wizard.
Test that the new project works.
Copy relevant code from your old project into the new project.
The new project wizard is pretty fool-proof and very easy to use to get a working JavaFX project up and running in less than a minute.
The wizard generated project has the following features:
Simple working sample code for a small application.
Makes use of JavaFX graphics, controls, fxml.
Configures a maven or gradle project to use JavaFX, with appropriate maven artifact dependencies for basic development.
Uses recent, reasonably up-to-date JavaFX modules, with consistent versions (which is something many beginners often don't do).
Adds a module-info.java file that works for an FXML based JavaFX application (will also work if you don't use FXML).
Demonstrates placing an FXML file in a resource directory, and looking it up as a resource at runtime (which is something many, many beginners get wrong).
Properly separates a Controller class from the Application class (which is also something many beginners get wrong).
Demonstrates the proper use of #FXML injection based on ids in an FXML file (which is also something many beginners get wrong).
Does not require the openjfx JavaFX SDK download (because JavaFX module dependencies are sourced through maven).
Does not require manually setting VM arguments to run the application (because the appropriate module statements are in the module-info.java file rather than a VM command line).
Allows execution and debugging of the JavaFX application directly from the IDE.
Includes the openjfx maven plugin.
You can probably ignore this or delete it from the generated project file if you want.
A couple of thoughts on the openjfx-maven plugin:
For most development, I don't think you need to use it.
If you don't need it you can remove it from your project.
The openjfx maven plugin is not required for the execution of the application
Although you could use it for that if you really wanted to, it doesn't provide any advantage over direct execution in the IDE as far as I can tell.
The openjfx maven plugin can be useful for building jlink based distribution if that is something you wish to do.
The openjfx maven plugin cannot package your application using jpackage, at least at the moment:
if that is something you wish to do, investigate JPackageScriptFX, the ackman maven jpackage plugin or the badass jlink or runtime plugins, or some alternative tool like invoking jpackage directly.
Prior Answer
Some of the info in this prior answer is still useful for understanding background information on Java platform modularity and JavaFX.
Quick summary, you can do either:
Include the JavaFX modules via --module-path and --add-modules like in José's answer.
OR
Once you have JavaFX libraries added to your project (either manually or via maven/gradle import), add the module-info.java file similar to the one specified in this answer. (Note that this solution makes your app modular, so if you use other libraries, you will also need to add statements to require their modules inside the module-info.java file).
This answer is a supplement to Jose's answer.
The situation is this:
You are using a recent Java version, e.g. 13.
You have a JavaFX application as a Maven project.
In your Maven project you have the JavaFX plugin configured and JavaFX dependencies setup as per Jose's answer.
You go to the source code of your main class which extends Application, you right-click on it and try to run it.
You get an IllegalAccessError involving an "unnamed module" when trying to launch the app.
Excerpt for a stack trace generating an IllegalAccessError when trying to run a JavaFX app from Intellij Idea:
Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
at java.base/java.lang.Thread.run(Thread.java:830)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module #0x45069d0e) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module #0x45069d0e
at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056)
at org.jewelsea.demo.javafx.springboot.Main.start(Main.java:13)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
Exception running application org.jewelsea.demo.javafx.springboot.Main
OK, now you are kind of stuck and have no clue what is going on.
What has actually happened is this:
Maven has successfully downloaded the JavaFX dependencies for your application, so you don't need to separately download the dependencies or install a JavaFX SDK or module distribution or anything like that.
Idea has successfully imported the modules as dependencies to your project, so everything compiles OK and all of the code completion and everything works fine.
So it seems everything should be OK. BUT, when you run your application, the code in the JavaFX modules is failing when trying to use reflection to instantiate instances of your application class (when you invoke launch) and your FXML controller classes (when you load FXML). Without some help, this use of reflection can fail in some cases, generating the obscure IllegalAccessError. This is due to a Java module system security feature that does not allow code from other modules to use reflection on your classes unless you explicitly allow it (and the JavaFX application launcher and FXMLLoader both require reflection in their current implementation in order for them to function correctly).
This is where some of the other answers to this question, which reference module-info.java, come into the picture.
So let's take a crash course in Java modules:
https://www.baeldung.com/java-9-modularity
The key part is this:
4.9. Opens
If we need to allow reflection of private types, but we don't want all
of our code exposed, we can use the opens directive to expose specific
packages.
But remember, this will open the package up to the entire world, so
make sure that is what you want:
module my.module { opens com.my.package; }
So, perhaps you don't want to open your package to the entire world, then you can do:
4.10. Opens … To
Okay, so reflection is great sometimes, but we still want as much security as we can get from encapsulation. We can selectively open our packages to a pre-approved list of modules, in this case, using the opens…to the directive:
module my.module {
opens com.my.package to moduleOne, moduleTwo, etc.;
}
So, you end up creating a src/main/java/module-info.java class which looks like this:
module org.jewelsea.demo.javafx.springboot {
requires javafx.fxml;
requires javafx.controls;
requires javafx.graphics;
opens org.jewelsea.demo.javafx.springboot to javafx.graphics,javafx.fxml;
}
Where org.jewelsea.demo.javafx.springboot is the name of the package which contains the JavaFX Application class and JavaFX Controller classes (replace this with the appropriate package name for your application). This tells the Java runtime that it is OK for classes in the javafx.graphics and javafx.fxml to invoke reflection on the classes in your org.jewelsea.demo.javafx.springboot package. Once this is done, and the application is compiled and re-run things will work fine and the IllegalAccessError generated by JavaFX's use of reflection will no longer occur.
But what if you don't want to create a module-info.java file
If instead of using the Run button in the top toolbar of IDE to run your application class directly, you instead:
Went to the Maven window on the side of the IDE.
Chose the JavaFX maven plugin target javafx.run.
Right-clicked on that and chose either Run Maven Build or Debug....
Then the app will run without the module-info.java file. I guess this is because the maven plugin is smart enough to dynamically include some kind of settings that allows the app to be reflected on by the JavaFX classes even without a module-info.java file, though I don't know how this is accomplished.
To get that setting transferred to the Run button in the top toolbar, right-click on the javafx.run Maven target and choose the option to Create Run/Debug Configuration for the target. Then you can just choose Run from the top toolbar to execute the Maven target.
None of the above worked for me. I spent too much time clearing other errors that came up. I found this to be the easiest and the best way.
This works for getting JavaFx on Jdk 11, 12 & on OpenJdk12 too!
The Video shows you the JavaFx Sdk download
How to set it as a Global Library
Set the module-info.java (i prefer the bottom one)
module thisIsTheNameOfYourProject {
requires javafx.fxml;
requires javafx.controls;
requires javafx.graphics;
opens sample;
}
The entire thing took me only 5mins !!!
It is 2021 and JetBrains updated their IDE. The other questions about this error message are closed and point here.
Error: JavaFX runtime components are missing, and are required to run this application
If you have followed all of the other steps in these answers (eg. Libraries, --module-path, --add-modules, version matching JDK and JavaFX), and you still see this compile error, make sure your run/compile configuration has --module-path and --add-modules as VM Options and not Program Arguments in IntelliJ.
Open Run/Debug Configurations
Open Modify Options dropdown
Click Add VM Options
A very good explanation can be found at
https://edencoding.com/runtime-components-error/
including
Giving reflective access to your module
Giving other access to your module
and total, we need, adding to the above answers, add exports to your module definition
module my.project {
requires javafx.fxml;
requires javafx.controls;
opens my.project to javafx.graphics;
exports my.project;
}
add in VM options, (In run configuration), this line:
--module-path yourpathwheresdkislocated/lib --add-modules=javafx.controls,javafx.fxml
and if you want to run your jar application from terminal, put this
java --module-path yourpathwheresdkislocated/lib --add-modules=javafx.controls,javafx.fxml -jar YourJar.jar

How to deploy a JavaFX project with maven, including custom and non-modular dependencies?

I am currently in the process of trying to deploy my JavaFX application (either with a jar or an installer, however an installer would be preferred). I have seen some sources point to using jlink, in which I have tried to no avail.
While I would have no problem building normally with jlink, I am trying to include a custom serialization utility I made with Maven and Java 17 (no JavaFX, but it is a single modular with a module-info). To import this into my project, I am simply adding it as a dependency. Additionally, this dependency requires SnakeYAML, which I don't believe is a modular project? (Important later)
Now, with this dependency, if I try to run javafx:jlink, I typically get an error like "jlink does not work with automatic modules" (in reference to my serialization utility).
My setup:
JavaFX 17.0.1
JDK 17.0.1
Maven 3.8.4
IntelliJ IDEA ultimate
So, my main two questions:
Should I even bother with jlink, especially if I am trying to get an installer?
With modular projects like my JavaFX project, how do I add dependencies from other modular projects (and also, within the serialization utlity, somehow shade SnakeYAML) and allow them to be compiled with JavaFX?
Should I even bother with jlink, especially if I am trying to get an installer?
No.
You can make use of jlink during the process, but, in my experience, it is not necessary. Also, the images jlink creates can be a little difficult to integrate with what is required by jpackage, which you will need to use anyway.
Instead, use jpackage, not jlink if you want an installer.
jpackage can both link your application and create an installer, but jlink can only link and cannot create an installer.
With modular projects like my JavaFX project, how do I add dependencies from other modular projects (and also, within the serialization utlity, somehow shade SnakeYAML) and allow them to be compiled with JavaFX?
Don’t shade jars when packaging, it is not necessary. Also, if the jars are modular, it will break their modularity and they might not work (for example the JavaFX jars are not supported when shaded into a jar).
To add compile dependencies, you are already using Maven, just use its compile dependency mechanism.
For jar dependencies which you have created yourself, use the Maven install command to install the dependencies into your local repository, or use the install facilities in your repository manager (e.g. jfrog artifactory), if you use one.
The modern maven build process and the IDE integrations (at least Idea anyway) will automatically configure the correct paths for compilation of the declared dependencies so that they are available from the module path if they are modular and the class path or as an automatic module if they are not modular.
Include the dependent jars in your package. This can be done two ways:
if the jars are modular, link the jars into the runtime image included in the package:
Both jlink and jpackage can do this, but when creating an installer, use jpackage for the linking not jlink as jpackage will ensure all files in the image are in the right location for the installer, but jlink will not, in my experience using Java 17 tools.
if the jars are not modular, then include them in a lib directory in the package. In the startup script for your application, which is included in the package, place the lib directory for the non-modular library files on the class path, so that they can be found.
Additionally, this dependency requires SnakeYAML, which I don't believe is a modular project?
Follow the tutorial at:
https://github.com/dlemmermann/JPackageScriptFX
A description of JPackageScriptFX:
demonstrates how projects can use scripts to build self-contained, platform-specific executables and installers of their JavaFX applications via the jdeps, jlink, and jpackage tools
the scripts do not try to create a fully modularized solution but instead try to enable existing projects / applications, which often use non-modularized 3rd party dependencies, to be packaged

Intellij: Java 11: export module: package not found {module not found}, module-info.java

I'm trying to create a simple modular programming application.
My project consists of two modules-
com.module.model
com.module.util
when I'm trying to export the module com.module.model in module-info.java.
IntelliJ cannot find the package to import.
(However it should give me the error of module not found)
The same problem stands for 'requires module' too.
I have provided all the modules in the dependencies for com.module.model
Solutions I already tried-
Build the modules separately (before adding the export line) and the whole project (maven clean install) as whole.
Invalidated caches and restarted.
SDK and Language level is set to 11.
You need to create those packages com.module.model and the like within the java folder of your IntelliJ project.
Within IntelliJ, the directory that you've named as com.module.model is the "IntelliJ module" name and has no relation with the "Java module system", in that you would be using the artifact generated out of this project.
To add a screenshot on the similar lines as of the question. It would look like:

Java 9, Jigsaw and automatic modules

Java 9 / 10. I have been struggling with a simple project for more than a week.
As you can see in the picture, I want to use commons-collections as an automatic module (I have tried to add it with maven but that did not work out well).
So, I have red that I need to put the jar onto the module-path. Where does IntelliJ take this modulepath from? How can I tell the IDE to add commons-collections into the project so that
1. the compiler can find it at compile time and
2. Maven can find it at build time?
Anyone can help?
EDIT:
I have tried to add it in the project-structure dialog as a module dependency in all kinds of different combinations. I have literally tried hundreds of things, moved the jar around in the structure and I cannot find a simple enough doc to tell me how to do this.
I have used compiler options to add "--module-path automatic" (module specific and general compile options) in order to make IDEA find the thing and let Java make an automatic module out of it.
You need to add a library entry first, to make it available under Modules:
Step 1: Add a library (Add -> Java -> jar file)
Step 2: Select the module (remember to click "Apply")
After that, the module-info.java file will be successfully validated:
Intellij uses a module path if you run a program from an (intellij) module containing module-info.java, otherwise it will use a classpath.
I tried importing common4 as a module, it does seem to work for me, but I had to use a different 'requires' argument as compared to yours. Your 'requires' is 'commons.collections4', mine is 'org.apache.commons.collections4' (check the commons4 manifest entry for the highlighted Automatic-Module-Name and use that instead).
If the Automatic-Module-Name is missing from the commons4 manifest (it is absent from version 4.1 and earlier), Java may not detect the jar as a module if the name contains digits or illegal characters. Some maven repository jars therefore will not work and intelli will not see those jars as modules.
You can also check for a bad filename by using the following command:
jar --file=/path/to/jar --describe-module
If the command fails, it's likely that the jar does not have an Automatic-Module-Name entry and that the filename is poorly named.
ok
jar --file=C:\temp\jigsaw1-1.0.jar --describe-module
bad
jar --file=C:\temp\jigsaw1.0.jar --describe-module`
'jigsaw1.0: Invalid module name: '0' is not a Java identifier'
Some maven jars may therefore fail to be detected as modules as they tend to look similar.

Categories

Resources