JavaFX16: Unsupported JavaFX configuration: classes were loaded from 'unnamed module #...' - maven

I have a Maven multi-module project on IntelliJ that produces 3 jars, 2 of which are executables and the other one is for commmon resources.
One of the executable modules has a main class that asks if the user wants to start the program with CLI or GUI.
Running this main from IntelliJ works without problem, instead when I use Maven to make the jar (using maven shade):
mvn package -pl myModule -am
and then launch the jar with GUI option, this warning appears:
com.sun.javafx.application.PlatformImpl startup
WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module #...'
The GUI then starts without problems.
How can I get rid of this warning?
The JDK of my project is openJDK 16 (I've already added module-info.java in order to work with javafx), openJFX 16, maven shade plugin 3.2.4, maven compiler plugin 3.8.1.
If there's need to add furthermore information, I'll add them.

It seems that maven is shading the JavaFX jars into a single fat jar.
Shading multiple modules into the same jar is not possible, because a jar can only contain 1 module. So, I suppose the shade plugin resolves that problem by removing the module-info files of the dependencies it's using, which means the JavaFX code will not be loaded as a module, and you get a warning like this.
I think the only way to get rid of the warning is to not use shading, but keep the JavaFX modules as separate jar files, that you then put on the module path when running the application.

Related

Hot reloading a multi-module spring boot application with gradle

I'm trying to convert a project from maven to gradle, but I'm having trouble getting hot reloading to work the same way. I can't show the actual project so I've created two identical very simple projects. One with maven one with gradle. These projects contain two modules:
project
|____api
|____lib
The /api module contains a spring-boot app which depends on code from the /lib module
In the maven project I can change code in either of these modules and recompile either with my IDE (intellij) or with the maven cli and spring-boot-devtools will hot reload the application. However in the gradle version it only successfully hot reloads code that has changed in the /api module.
From what I gathered this seems like a classpath issue. If you run gradle or maven in debug mode it prints out the classpath it passes when it starts the application. Maven includes <project_dir>/lib/target/classes/kotlin/main. However gradle only includes <project_dir>/lib/build/libs/lib.jar
I'm very new to gradle to I might have some of the build configuration messed up. Here are the two project repo's:
Maven: https://github.com/Perry-Olsson/mvn-hot-reload
Gradle: https://github.com/Perry-Olsson/gradle-hot-reload

How to pack a jar without dependency classes in gradle similar to maven

How to write a gradle script so that the application jar should be packed without dependency classes similar to maven jar package
The application JAR is always without dependencies, except you use special plugins to create a "fat" JAR where the dependencies are included. If you ask how to set up a Gradle build at all, you should start reading the Users Guide.
If you are trying to package a jar from your Android app or library:
I ran into this question because gradle would include 3rd party libraries into my jar when running gradle assembleRelease.
The contents of the jar then looked like this:
com/android/...
/myCompany/...
For some reason this did not happen when building for debug. Finally I found that changing:
compile 'com.android.support:recyclerview-v7:23.0.0'
to
provided 'com.android.support:recyclerview-v7:23.0.0'
would not include the 3rd party libs ...

Intellij: How to add module compile output to web-inf/classes in stead of web-inf/lib?

I'm using maven to set up a war project in IntelliJ and run in it GlassFish. The war project depends on several other modules. When I run the project in debug mode, hot deploying codechanges of the changes results in NoClassDefFound exceptions. I found out that IntelliJ tries to redeploy the module jar but GlassFish keeps a lock on it so it fails. All the classes in that module are now unavailable, causing these NoClassDefFound exceptions.
IntelliJ generates the artifacts this way: the dependent modules are all added as jar dependencies as if they were external dependencies:
Now, when I remove the jar dependencies, IntelliJ tells me it found some missing dependencies and proposes a fix to add the missing dependencies.
Fixing those dependencies will add the module compile output to the WEB-INF\classes folder.
Once deployed, IntelliJ has no problem anymore hot-deploying changed classes to GlassFish since there's no jar to keep a lock on.
Problem
Every time I make a change to any pom.xml, IntelliJ refreshes the artifacts automatically, which is fine: I definitely want to see those changes appear in the artifact. However, all modules are added as jar dependencies again.
Question
How can I make sure that IntelliJ adds the compile output of project modules to WEB-INF\classes and not to WEB-INF\lib?
I found this question but it has two problems:
There are many module dependencies so if possible I'd like to avoid specifying them all one by one in the unpack goal
IntelliJ seems to ignore this. When I add that configuration and while it works perfectly in a maven commandline build, IntelliJ still refuses to add the module compile output to the WEB-INF\classes dir
I found a bugreport that asks about the same thing but for me it's hard to believe there's no way to solve this problem. Other webapp developers using IntelliJ must have this same issue, making it difficult to hot-deploy code changes, unless I did something wrong in my pom configuration.

How to manage compile time dependencies in Maven

Trying to avoid the use of jargon, so that I don't get misinterpreted.
Here is the scenario, My project requires a jar in order to get compiled(let say x.jar). My project get once compiled gets converted into a WAR file, which gets deployed somewhere.
Now I want x.jar just to be there for my project to compile and it should not be packed(or part of) inside WAR file.
How can I do this in Maven ? should I used dependency scope as "provided"
You are right, as stated in the Maven FAQs, the scope to use is provided,
How do I prevent including JARs in WEB-INF/lib? I need a "compile only" scope!
The scope you should use for this is provided. This indicates to Maven that the dependency will be provided at run time by its container or the JDK, for example.
Dependencies with this scope will not be passed on transitively, nor will they be bundled in an package such as a WAR, or included in the runtime classpath.
To quickly try it out, you can use
mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-webapp
to generate a "toy webapp" project, add a dependency to your project and set it to <scope>provided</scope>.

how to auto build jar by maven when i modify one java class?

I have install m2eclipse plug-in for eclipse. I built a multi-module project by maven, each module are dependent, when i write a class,the eclipse can't automatically compile the class to jar file and install to M2 repository,i need to run MVN install command, then other modules can be reference the jar file, this is too much trouble, is there any good way to solve this problem?
This is because the "install" phase does not belong to m2eclipse's interesting lifecycle phases. In short, Eclipse and Maven build cycles differ a lot, and m2eclipse has a map that binds particular phases — and "install" is, by default, not mapped.
This map can be, however, configured in the POM of your project (ideally, the main POM). See: M2E_plugin_execution_not_covered

Resources