0

i have a question about Mavenbuilds. I wanted to try to make a little javafx testprogram in a mavenbuild in Eclipse IDE, i am using JavaSE 18 and JavaFX 19. so now if i want to run-> Maven build... and set the goal "clean javafx:run" i get this Failure / Error message:

[[1;34mINFO[m] Scanning for projects...
[[1;34mINFO[m] 
[[1;34mINFO[m] [1m---------------------< [0;36morg.openjfx:HauserProgram[0;1m >----------------------[m
[[1;34mINFO[m] [1mBuilding HauserProgram 0.0.1-SNAPSHOT[m
[[1;34mINFO[m] [1m--------------------------------[ jar ]---------------------------------[m
[[1;34mINFO[m] 
[[1;34mINFO[m] [1m--- [0;32mmaven-clean-plugin:2.5:clean[m [1m(default-clean)[m @ [36mHauserProgram[0;1m ---[m
[[1;34mINFO[m] Deleting D:\eclipse-workspace\javafxmav\target
[[1;34mINFO[m] 
[[1;34mINFO[m] [1m>>> [0;32mjavafx-maven-plugin:0.0.8:run[m [1m(default-cli)[0;1m > [0;1mprocess-classes[m @ [36mHauserProgram[0;1m >>>[m
[[1;34mINFO[m] 
[[1;34mINFO[m] [1m--- [0;32mmaven-resources-plugin:2.6:resources[m [1m(default-resources)[m @ [36mHauserProgram[0;1m ---[m
[[1;34mINFO[m] Using 'UTF-8' encoding to copy filtered resources.
[[1;34mINFO[m] Copying 3 resources
[[1;34mINFO[m] 
[[1;34mINFO[m] [1m--- [0;32mmaven-compiler-plugin:3.1:compile[m [1m(default-compile)[m @ [36mHauserProgram[0;1m ---[m
[[1;34mINFO[m] Changes detected - recompiling the module!
[[1;34mINFO[m] Compiling 6 source files to D:\eclipse-workspace\javafxmav\target\classes
[[1;34mINFO[m] -------------------------------------------------------------
[[1;31mERROR[m] COMPILATION ERROR : 
[[1;34mINFO[m] -------------------------------------------------------------
[[1;31mERROR[m] /D:/eclipse-workspace/javafxmav/src/main/java/module-info.java:[6,24] module not found: javafx.base
[[1;31mERROR[m] /D:/eclipse-workspace/javafxmav/src/main/java/module-info.java:[7,24] module not found: javafx.controls
[[1;31mERROR[m] /D:/eclipse-workspace/javafxmav/src/main/java/module-info.java:[8,35] module not found: javafx.fxml
[[1;31mERROR[m] /D:/eclipse-workspace/javafxmav/src/main/java/module-info.java:[9,35] module not found: javafx.graphics
[[1;31mERROR[m] /D:/eclipse-workspace/javafxmav/src/main/java/module-info.java:[11,32] module not found: org.apache.poi.poi
[[1;34mINFO[m] 5 errors 
[[1;34mINFO[m] -------------------------------------------------------------
[[1;34mINFO[m] [1m------------------------------------------------------------------------[m
[[1;34mINFO[m] [1;31mBUILD FAILURE[m
[[1;34mINFO[m] [1m------------------------------------------------------------------------[m
[[1;34mINFO[m] Total time:  0.683 s
[[1;34mINFO[m] Finished at: 2022-11-01T12:45:40+01:00
[[1;34mINFO[m] [1m------------------------------------------------------------------------[m
[[1;31mERROR[m] Failed to execute goal [32morg.apache.maven.plugins:maven-compiler-plugin:3.1:compile[m [1m(default-compile)[m on project [36mHauserProgram[m: [1;31mCompilation failure[m: Compilation failure: 
[[1;31mERROR[m] /D:/eclipse-workspace/javafxmav/src/main/java/module-info.java:[6,24] module not found: javafx.base
[[1;31mERROR[m] /D:/eclipse-workspace/javafxmav/src/main/java/module-info.java:[7,24] module not found: javafx.controls
[[1;31mERROR[m] /D:/eclipse-workspace/javafxmav/src/main/java/module-info.java:[8,35] module not found: javafx.fxml
[[1;31mERROR[m] /D:/eclipse-workspace/javafxmav/src/main/java/module-info.java:[9,35] module not found: javafx.graphics
[[1;31mERROR[m] /D:/eclipse-workspace/javafxmav/src/main/java/module-info.java:[11,32] module not found: org.apache.poi.poi
[[1;31mERROR[m] -> [1m[Help 1][m
[[1;31mERROR[m] 
[[1;31mERROR[m] To see the full stack trace of the errors, re-run Maven with the [1m-e[m switch.
[[1;31mERROR[m] Re-run Maven using the [1m-X[m switch to enable full debug logging.
[[1;31mERROR[m] 
[[1;31mERROR[m] For more information about the errors and possible solutions, please read the following articles:
[[1;31mERROR[m] [1m[Help 1][m http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

here is my module-info.java:

module HauserProgram {

    exports de.hauserwein;

    requires java.sql;
    requires javafx.base;
    requires javafx.controls;
    requires transitive javafx.fxml;
    requires transitive javafx.graphics;
    requires java.desktop;
    requires org.apache.poi.poi;

    opens de.hauserwein to javafx.fxml, javafx.base, javafx.controls, javafx.graphics;
    

}

and my pom.xml:

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.openjfx</groupId>
  <artifactId>HauserProgram</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  <properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 <maven.compiler.source>18</maven.compiler.source>
 <maven.compiler.target>18</maven.compiler.target>
</properties>
  
  <dependencies>
  
  <dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>8.0.30</version>
  </dependency>
  
  <dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-fxml</artifactId>
    <version>18</version>
  </dependency>
  
  <dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>5.2.3</version>
</dependency>

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-to-slf4j</artifactId>
    <version>2.19.0</version>
</dependency>

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>5.2.3</version>
</dependency>


  </dependencies>
  
  
    
  <build>
    <plugins>
    <plugin>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-maven-plugin</artifactId>
        <version>0.0.8</version>
        <configuration>
<mainClass>de.hauserwein/Main.java</mainClass>

</configuration>
    </plugin>
    </plugins>
  </build>

</project>

i tried to add the javafx sdk to the buildpath, tested some different javafx versions 18/19 in the pom.xml, and wanted to add org.openjfx to the module-info.java file...

if i start it with "Run As JavaApplication" it will work, only the export to an runable file wont work.

  • You only need these two module requirements for JavaFX: `requires javafx.controls;` and `requires javafx.fxml;`, nothing needs to be `transitive`. You are using JavaFX Maven modules, you don't need the SDK (uninstall it and remove all places you tried to reference it). – jewelsea Nov 01 '22 at 12:36
  • But none of that should matter with regards to your `module not found` compilation issue. I don't know what is causing that. Maybe you are using some ancient version of Maven which is not aware of modular java. (In this context I mean java platform modules not maven modules). – jewelsea Nov 01 '22 at 12:36
  • Maybe review the documentation on [JavaFX+Eclipse+Maven+Modular](https://openjfx.io/openjfx-docs/), and make sure that the sample project with that combo works in your environment before trying to build your own app using that combo. – jewelsea Nov 01 '22 at 12:45
  • "export to an runable file wont work" -> what is that? what does wont work mean? That seems like a different issue from the "module not found" issue for "clean javafx:run". See [packaging info in the JavaFX tag](https://stackoverflow.com/tags/javafx/info), for options on packaging JavaFX apps for distribution (trying to use any built-in IDE function for that is currently not recommended because, as far as I know, none of them work). – jewelsea Nov 01 '22 at 12:49
  • Your module is named `HauserProgram`, so `de.hauserwein/Main.java` is wrong. Probably the main class is in package `de.hauserwein` (just guessing). So the main class would be `HauserProgram/de.hauserwein.Main`. See the [java man](https://docs.oracle.com/en/java/javase/19/docs/specs/man/java.html) for info on how to specify a modular main class. – jewelsea Nov 01 '22 at 13:00
  • thx for it. now i updated the module-info, and i uninstalled the sdk, nothing works. Later i will test the link you posted and try the sample project. – Christian Stempfle Nov 01 '22 at 13:29
  • I think the javafx-maven-plugin will [make use of the `JAVA_HOME` environment variable if it is defined](https://github.com/openjfx/javafx-maven-plugin/blob/b63e0367a1e29d205f937c0c276c03d08557df4a/src/main/java/org/openjfx/JavaFXBaseMojo.java#L527), so, if you have defined that variable, make sure [`JAVA_HOME` is set correctly](https://www.baeldung.com/java-home-on-windows-7-8-10-mac-os-x-linux). – jewelsea Nov 02 '22 at 01:10
  • I tried to create the maven javafx sample program with the code ```mvn archetype:generate \ -DarchetypeGroupId=org.openjfx \ -DarchetypeArtifactId=javafx-archetype-simple \ -DarchetypeVersion=0.0.3 \ -DgroupId=org.openjfx \ -DartifactId=sample \ -Dversion=1.0.0 \ -Djavafx-version=19``` where does i have to type this into? When i type it in cmd it wont work, because my computer said mvn is an invalid command. And what do you mean with java_home? Does i have to put maven in it? I have there only java 18 in it – Christian Stempfle Nov 02 '22 at 06:30
  • I linked info on JAVA_HOME already. If it is not defined, it probably doesn’t matter, but if it is defined then it should be correct. No you don’t put maven in JAVA_HOME, it is where Java is, not maven. For mvn, it is just an executable command, if the directory with the executable is in your PATH, then you can run it from a command prompt without qualification, otherwise you must provide the full path, same as any other executable. See [maven setup](https://stackoverflow.com/questions/10649707/maven-mvn-command-not-found). – jewelsea Nov 02 '22 at 06:51
  • thx. maven wasnt installed on my computer. now i made the maven setup and the command "mvn" works. but the failure is still there. – Christian Stempfle Nov 02 '22 at 15:56
  • @jewelsea - thx after the maven setup the mvn command works... and now i have create a sample project. everything is still working. but now the executable jar file i have created didnt open with double click :( – Christian Stempfle Nov 03 '22 at 16:36
  • Running an executable jar with a double click is a different problem than the build issue from your question, you can ask it as a new question with updated, relevant information. For information on how to package your application for distribution and execution, see the [packaging information in the JavaFX tag](https://stackoverflow.com/tags/javafx/info). Perhaps you may want to use a tool such as `jpackage` to create an installer for your application. The installer is capable of creating a shortcut for the OS allowing the installed application to be executed by double-click. – jewelsea Nov 03 '22 at 21:04

1 Answers1

1

Firstly, make sure you have all the dependencies in your pom:

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

Then, it sounds like you have your dependencies on the build path in eclipse, rather than the maven project. Run mvn clean install to resolve the dependencies.

(And please don't use <groupId>org.openjfx</groupId> for your artifacts. It causes unnecessary confusion.)

Vinz
  • 483
  • 1
  • 10
  • I don't advise providing a classifier, instead the build system can work out what classifier to use from the platform you are building on. Also, javafx-controls and javafx-fxml will depend on javafx-graphics so you don't need to explicitly specify javafx-graphics, it will be brought in automatically via the transitive dependency. – jewelsea Nov 01 '22 at 12:42
  • I would agree that there is no point specifying ` javafx-graphics` if I leave out the classifier. But why would you advise against using a classifier altogether? I recently built (on windows) a project for both Win and Mac, and simply specifying the classifier seems the easiest way to me. Also, it's explicit instead of inferred during the build phase, which I also like. Is there something I am unaware of? – Vinz Nov 01 '22 at 12:58
  • 1
    It is easier to make mistakes if you provide classifiers. For instance, you provide a classifier only for the graphics module, but the other JavaFX modules should all have classifiers too. It is more difficult for new people to understand, because they need to get the classifiers right (e.g. they need multiple classifiers to support M1 and Intel macs). It is only needed for a cross platform build, which is usually used in conjunction with a shaded jar, which is not an officially supported configuration. – jewelsea Nov 01 '22 at 13:05
  • With regards to classifier specification, I recommend [convention over configuration](https://en.wikipedia.org/wiki/Convention_over_configuration). If you have unusual build requirements such as a multi-platform shaded jar, then go ahead and provide the multiple classified dependencies, otherwise don't. – jewelsea Nov 01 '22 at 13:07
  • 1
    To be clear, I built the project for Win and Mac seperately, not as one cross-platform jar. I just built it on windows for intended use on Mac, therefore I resorted to the classifiers. But I can see how this is out of place for this Question and I will remove it from my answer, thanks. – Vinz Nov 01 '22 at 13:17
  • "I built the project for Win and Mac seperately, not as one cross-platform jar. I just built it on windows for intended use on Mac, therefore I resorted to the classifiers." -> yes, this would be a recommended usage for classifiers in an unconventional build environment, perhaps in conjunction with the Maven profile mechanism to select the target platform to build for. – jewelsea Nov 01 '22 at 13:20
  • i tried ```mvn clean install``` , it sais "Unknown lifecycle phase "mvn".", is this a problem with the archetypes like jewelsea told in the upper answer? – Christian Stempfle Nov 01 '22 at 13:47
  • it sais "Unknown lifecycle phase "mvn" -> that would imply that it is running `mvn mvn` I think (e.g. `mvn` is being passed as an argument to `mvn`), I couldn't tell you why. – jewelsea Nov 01 '22 at 19:50