我不得不切换到来自JDK8的openJDK,但无法使用maven编译程序。 这对我来说是新事物,经过数天的搜寻之后,我对版本的困惑比以前更加困惑。
我找不到:
这就是我在Eclipse中所做的
当我从GIT刚导入项目时,它运行时没有任何错误。 在我编译它或通过Maven更新项目之后,出现了许多不同的错误,程序不再可运行。 我注意到,每次更新时,maven都会将我的Project JRE设置为[J2SE-1.5]。我该如何预防?
这真的很奇怪。在类内部,我得到了无法找到某些内容的编译器错误,但是在我的包资源管理器中,一切似乎都很好:
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>
我觉得我的代码没有什么问题,但这是当前的错误:
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
我从一个新的类中调用我的主类,因为似乎有一个错误。
NewMain类:
package srcMain;
public class NewMain {
public static void main(String args[] ) throws Exception {
Main.main(args);
}
}
主要班级:
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);
}
}
我将项目导入到另一个环境,现在有一个新的错误。它找不到启动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)
答案 0 :(得分:1)
我应该使用最新版本的openJDK吗? (目前为13)
您可以使用任何当前可用的版本/使用寿命终止的版本。目前(2019年10月):
(您甚至可以使用寿命终止版本,但这是不可取的,因为几乎没有可用的安全补丁。)
OpenJFX是否必须与OpenJDK的版本匹配?
在Java 11之前,由于OpenJFX与OpenJDK(或Oracle JDK或JRE)捆绑在一起,这个问题尚无定论
因此版本不需要匹配。
Maven:我必须用13的源和目标来编译它,还是可以用1.8使其与JRE1.8兼容
目前您在问什么不清楚。如果打算在要构建的相同版本平台上运行,则源版本和目标版本应与该Java版本匹配。通常,您可以选择在较旧平台上构建的类,并在较新平台上运行它们。 (如果您使用的是不推荐使用的已删除的类或方法,则为例外。)
如果要在较新的平台上构建并在较旧的平台上运行,则需要设置源和目标版本以匹配较旧的平台版本。但这可能还不够。您还需要进行匹配以确保您的代码不依赖于旧的运行时库中不支持的新访问类和方法。
相同的原则适用于JavaFX应用程序。如果希望JavaFX应用程序在Java 8上运行,则最好在Java 8上构建。如果在Java 11上构建,则需要使用8作为源版本和目标版本,并且需要限制使用仅有JavaFX 8 API。
您的异常似乎是由尚未纠正的编译错误引起的。 您不应运行带有编译错误的代码。在运行代码之前 修复所有编译错误。
最终的匹配错误是由于调用Main
类中不存在的静态方法引起的。实际上,launch
方法是Application
的静态方法,因此您需要这样调用它:
Application.launch(args);
静态方法未在Java中继承。
答案 1 :(得分:1)
解决方案: 所有的编译错误都是由通过Maven压缩OpenJFX库引起的。我通过删除所有存储库并使用mvn update project函数再次将其导入来解决了这个问题。