I had to switch to openJDK coming from JDK8 and I am not able to compile my program with maven. This is new to me and after days of googling I am more confused about the versions than I was before.
I could not find out:
- Am I supposed to use the latest version of openJDK? (which is currently 13)
- Does the openJFX has to match the version of openJDK?
- Maven: Do I have to compile it with source and target with 13 or is it possible with 1.8 to be compatible with JRE1.8
Here is what I did in Eclipse
- imported openJDK 13 into eclipse and set it as the default JDK.
- updated the pom.xml to maven compiler 3.8.1 and set the source and target to 13.
- added openJFX 13 dependencies
When I freshly import the project from GIT it runs without any errors. After I compile it or update the project via Maven I get a bunch of different errors and the program is not runnable anymore. I noticed that maven sets my Project JRE to [J2SE-1.5] every time I update it. How do I prevent this?
This is really strange. Inside Class I get compiler erros that something cannot be found, but in my package explorer everything seems fine:
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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>IBE_Calculator</groupId>
<artifactId>IBE_Calculator</artifactId>
<version>IBE</version>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>main/resources</directory>
<includes>
<include>IBEDB.sqlite</include>
</includes>
</resource>
<resource>
<directory>res</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>13</source>
<target>13</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>main.java.srcMain.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version>
<configuration>
<mainClass>main.java.srcMain.Main</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/classes/libs2</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-base</artifactId>
<version>13</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>13</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>13</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>13</version>
</dependency>
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.12</version>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.8.11.2</version>
</dependency>
<dependency>
<groupId>org.dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.jgrapht</groupId>
<artifactId>jgrapht-ext</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>net.sourceforge.jexcelapi</groupId>
<artifactId>jxl</artifactId>
<version>2.6.12</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.5.0</version>
</dependency>
</dependencies>
<name>IBECalc</name>
</project>
I feel like theres nothing wrong with my code but here is the current error:
Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
at 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.Error: Unresolved compilation problems:
The method handle(WindowEvent) of type new EventHandler<WindowEvent>(){} must override a superclass method
The method run() of type new Runnable(){} must override a superclass method
at srcMain.Main$1.handle(Main.java:42)
at srcMain.Main$1.handle(Main.java:1)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.stage.Window.fireEvent(Window.java:1368)
at javafx.stage.Window$12.invalidated(Window.java:1122)
at javafx.beans.property.BooleanPropertyBase.markInvalid(BooleanPropertyBase.java:110)
at javafx.beans.property.BooleanPropertyBase.set(BooleanPropertyBase.java:145)
at javafx.stage.Window.setShowing(Window.java:1174)
at javafx.stage.Window.show(Window.java:1189)
at javafx.stage.Stage.show(Stage.java:273)
at srcMain.Main.start(Main.java:74)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
... 1 more
I call my Main class from a new Class, because there seems to be a bug.
Class NewMain:
package srcMain;
public class NewMain {
public static void main(String args[] ) throws Exception {
Main.main(args);
}
}
Class Main:
package srcMain;
import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;
import SQLite.*;
import javafx.application.*;
import com.sun.javafx.application.*;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;
import javafx.event.*;
import javafx.fxml.FXMLLoader;
import javafx.scene.*;
public class Main extends Application{
static SQLite db;
public static Boolean isSplashLoaded = false;
public static Boolean data_fin = false;
public static Stage parentWindow;
Stage stage = new Stage();
@Override
public void start(final Stage primaryStage) throws Exception{
/*
* �ffnet den Loading Screen und startet die Dateneinlesung
*/
try{
parentWindow = primaryStage;
FXMLLoader loader = new FXMLLoader(getClass().getResource("IBE_LoadScreen.fxml"));
loader.setController(new ControllerLoadScreen());
Parent root1 = (Parent)loader.load();
//wenn die GUI angezeigt wird, wird die Dateneinlesung gestartet
stage.addEventHandler(WindowEvent.WINDOW_SHOWN, new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent window){
Platform.runLater(new Runnable(){
@Override
public void run(){
try {
try {
readData();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
data_fin = true;
}
});
}
});
//wird der Close-Button gefr�ckt, schlie�t sich das gesamte Programm, nicht nur das Fenster
Platform.setImplicitExit(false);
stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
Platform.exit();
}
});
stage.setResizable(true);
stage.setTitle("Wegeentgelt-Kalkulator");
stage.setScene(new Scene(root1));
stage.show();
}catch(Exception e){
System.out.println("Cant load new window");
e.printStackTrace();
}
}
public void readData() throws SQLException, ParseException {
/*
* erstellt ein ExcelHandler Objekt und ruft alle Methoden auf
* die Daten von den Excel-Files einlesen.
*
* Wenn diese Daten fertig eingelesen wurden, wird die Main-Maske angezeigt.
*/
db.Hst();
db.Halte();
db.Marktsegment();
db.bstn();
db.basisdaten();
db.TFZ();
db.closeConnection();
data_fin = true;
//wenn die Daten eingelesen wurden �ffnet sich die Main-Maske
if(data_fin){
FXMLLoader loader = new FXMLLoader(getClass().getResource("IBECalc-Main_1024_768.fxml"));
loader.setController(new ControllerMain("1024x768"));
Parent root1;
try {
root1 = (Parent)loader.load();
stage.getScene().setRoot(root1);
stage.setResizable(true);
stage.setMinHeight(680);
stage.setMinWidth(1024);
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) throws SQLException{
//startet das Programm
db = new SQLite();
launch(args);
}
}
I imported the project to another environment and now there is a new Error. It can't find the Application Class to start the GUI.
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method launch(String[]) is undefined for the type Main
at srcMain.Main.main(Main.java:123)
at srcMain.NewMain.main(NewMain.java:6)
pom.xmlfile as well as a minimal reproducible example for the exception, please?srcMain.Main. According to the stack trace you posted, line 42 in fileMain.javais throwing an error. Seems like that line of code could be the@Overrideannotation.@Overrideannotations - they are not mandatory. (I don't think it will make things worse than they are now :-)