迁移到openJDK 13和openJFX 13 [英] Migrate to openJDK 13 and openJFX 13

查看:129
本文介绍了迁移到openJDK 13和openJFX 13的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不切换到来自JDK8的openJDK,但无法使用maven编译程序. 这对我来说是新的,经过数天的搜索后,我对版本的困惑比以前更加困惑.

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.

我找不到:

  • 我应该使用最新版本的openJDK吗? (目前为13)
  • openJFX是否必须与openJDK的版本匹配?
  • Maven:我必须用13的源和目标来编译它,还是可以用1.8使其与JRE1.8兼容

这就是我在Eclipse中所做的

Here is what I did in Eclipse

  • 将openJDK 13导入eclipse并将其设置为默认JDK.
  • 将pom.xml更新为maven编译器3.8.1,并将源和目标设置为13.
  • 添加了openJFX 13依赖项

当我从GIT刚导入项目时,它运行时没有任何错误. 在我编译它或通过Maven更新项目之后,出现了许多不同的错误,程序不再可运行. 我注意到,每次更新时,maven都会将我的Project JRE设置为[J2SE-1.5].我该如何预防?

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.

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的应用程序类.

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)

推荐答案

我应该使用最新版本的openJDK吗? (目前为13)

Am I supposed to use the latest version of openJDK? (which is currently 13)

您可以使用任何当前可用的版本/使用寿命终止的版本.目前(2019年10月):

You can use any version that is currently available / not end-of-life. At this time (October 2019):

  • 可以继续使用OpenJDK 8,直到至少2020年12月,
  • OpenJDK 9和现在有10个产品即将终止,
  • OpenJDK 11是最新的LTS版本,
  • OpenJDK 12现已停产,并且
  • OpenJDK 13是最新版本.
  • you could continue with OpenJDK 8 until at least December 2020,
  • OpenJDK 9 & 10 are now end-of-life,
  • OpenJDK 11 is the latest LTS version,
  • OpenJDK 12 is now end-of-life, and
  • OpenJDK 13 is the latest version.

(您甚至可以使用寿命终止版本,但这是不可取的,因为几乎没有可用的安全补丁.)

(You could even use an end-of-life version, but it is inadvisable because there are unlikely to be any security patches available.)

OpenJFX是否必须与OpenJDK的版本匹配?

Does the OpenJFX has to match the version of OpenJDK?

在Java 11之前,由于OpenJFX与OpenJDK(或Oracle JDK或JRE)捆绑在一起,这个问题尚无定论

Prior to Java 11 this question was moot as OpenJFX was bundled with OpenJDK (or Oracle JDK or JRE)

  • OpenJFX 11 (release notes) JDK 11 is recommended
  • OpenJFX 12 (release notes) requires JDK 11
  • OpenJFX 13 early access (release notes) requires JDK 11 or later. (This could be revised.)

因此版本不需要匹配.

Maven:我必须用13的源和目标来编译它,还是要用1.8来与JRE1.8兼容

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

目前您在问什么不清楚.如果打算在要构建的相同版本平台上运行,则源版本和目标版本应与该Java版本匹配.通常,您可以采用在较旧平台上构建的类,并在较新平台上运行它们. (如果您使用的是不推荐使用的已删除的类或方法,则为例外.)

It is not clear what you are asking here. If you intend to run on the same version platform that you are building for, then the source and target versions should match that Java version. As a general rule, you can take classes built on an older platform and run them on a newer platform. (The exception is if you are using deprecated classes or methods that have been removed.)

如果要在较新的平台上构建并在较旧的平台上运行,则需要设置源版本和目标版本以匹配较旧的平台版本.但这可能还不够.您还需要进行匹配以确保您的代码不依赖于旧的运行时库中不支持的新访问类和方法.

If you want to build on a newer platform and run on an older one, then you need to set the source and target versions to match the older platform version. But that may not be sufficient. You also need to match sure that your code doesn't depend on newly access classes and methods that are not supported in the older runtime libraries.

相同的原理适用于JavaFX应用程序.如果要使JavaFX应用程序在Java 8上运行,则最好在Java 8上构建.如果在Java 11上构建,则需要使用8作为源版本和目标版本,并且需要限制使用仅有JavaFX 8 API.

The same principles apply with JavaFX applications. If you want your JavaFX app to run on Java 8, it is best to build on Java 8. If you build on Java 11, you will need to use 8 as the source and target versions, and you will need to restrict yourself to using only JavaFX 8 APIs.

您的异常似乎是由尚未更正的编译错误引起的. 您不应运行带有编译错误的代码.请在运行代码之前 修复所有编译错误.

Your exceptions seem to be caused by compilation errors that have not been corrected. You should not run code with compilation errors. Fix all of the compilation errors before you run the code.

最终的匹配错误是由于调用了Main类中不存在的静态方法所致.实际上,launch方法是Application的静态方法,因此您需要这样调用它:

The final compikation error is due to calling a static method that doesn't exist in the Main class. In fact, the launch method is a static method of Application, so you need to call it like this:

    Application.launch(args);

静态方法未在Java中继承.

Static methods are not inherited in Java.

这篇关于迁移到openJDK 13和openJFX 13的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆