0

I know this question has been asked a lot but I could not find an answer that solved my problem.

When I try and run my Java program in Eclipse I get :

Error: Could not find or load main class tutorial2.Exterminator
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application

I am using javaFX and have it set up as per https://openjfx.io/openjfx-docs/#install-java

I have tried many of the solutions given on questions similar to this but no luck yet.

Should I be doing something different when I create the project or is there a simple solution that I just haven't clicked on yet?

Commmand line:

C:\Program Files\Java\jdk-11.0.2\bin\javaw.exe -Dfile.encoding=Cp1252 -p "C:\Program Files\JavaFX\javafx-sdk-11.0.2\lib\javafx.base.jar;C:\Program Files\JavaFX\javafx-sdk-11.0.2\lib\javafx.controls.jar;C:\Program Files\JavaFX\javafx-sdk-11.0.2\lib\javafx.fxml.jar;C:\Program Files\JavaFX\javafx-sdk-11.0.2\lib\javafx.graphics.jar;C:\Program Files\JavaFX\javafx-sdk-11.0.2\lib\javafx.media.jar;C:\Program Files\JavaFX\javafx-sdk-11.0.2\lib\javafx.swing.jar;C:\Program Files\JavaFX\javafx-sdk-11.0.2\lib\javafx.web.jar;C:\Program Files\JavaFX\javafx-sdk-11.0.2\lib\javafx-swt.jar" -classpath "C:\Users\jpcog\eclipse-workspace\tut2\bin" tutorial2.Exterminator

Below is a quick pic of my package explorer if that helps at all.

package explorer

Julien Powell
  • 186
  • 1
  • 14
  • please post code as code, not as a printscreen. – Stultuske Mar 12 '19 at 10:20
  • 2
    @Stultuske The pic is of the package explorer not the code – Julien Powell Mar 12 '19 at 10:21
  • 1
    there are many things that can go wrong and unfortunately some are/were bugs in eclipse, so debugging is hard ;) make sure the fx modules are on the runtime path: this should be handled automatically by eclipse but wasn't, last had problems when added as a user library as seems to be the case here - to enforce, add vm arguments both module-path and add-modules – kleopatra Mar 12 '19 at 11:04
  • If deleting the existing launch configuration and running again does not fix your issue, please add the command line to your question (in the launch configuration there is a button _Show Command Line_ at the bottom for that). It doesn't look like this is the full stack trace. If so, please add the full stack trace. – howlger Mar 12 '19 at 11:21
  • @howlger I have added it in to the question. – Julien Powell Mar 12 '19 at 11:27
  • 1
    @JulienPowell What do you get if you add `--add-modules=ALL-SYSTEM` as VM argument to your launch configuration? Alternative, in _Project > Properties: Java Build Path_, tab _Libraries_ move the JRE and JavaFX11 from the _Modulepath_ to the _Classpath_. – howlger Mar 12 '19 at 12:20
  • @howlger I changed the locations of the libraries and added --module-path "\path\to\javafx-sdk-11.0.2\lib" --add-modules=javafx.controls,javafx.fxml to the vm instructions. It now gives: Error occurred during initialization of boot layer java.lang.module. FindException: Module javafx.controls not found – Julien Powell Mar 12 '19 at 12:32
  • @JulienPowell `-p` is a shortcut for `--module-path`. All _Modulepath_ entries (specified in the _Java Build Path_, tab _Libraries_) are added via `-p` and that's contrary to `--module-path` as VM argument. So either add `--add-modules=ALL-SYSTEM` only (or more specific `--add-modules=javafx.controls,javafx.fxm` only) as VM argument to your launch configuration or move everything from the _Modulepath_ to the _Classpath_. – howlger Mar 12 '19 at 12:41
  • @howlger I actually just moved everything back from classpath to modulepath and it is now working perfectly. Looks like the step that was needed was the vm instructions from the getting started guide but it wasn't giving the expected error hence I never thought to use it. – Julien Powell Mar 12 '19 at 12:46
  • @JulienPowell The recommended way is either to use the classpath only (instead of also the modulepath) or to explicitly add the required modules in _Project > Properties: Java Build Path_, tab _Libraries_ via editing the _Is modular_ subnode (instead adding VM arguments to each launch configuration). – howlger Mar 12 '19 at 12:53

0 Answers0