简体   繁体   English

在Eclipse中将Java / JavaFX与Maven结合使用

[英]Using Java/JavaFX with Maven in Eclipse

I am working with Maven in Eclipse, in Windows. 我正在Windows中的Eclipse中使用Maven。 I made a JavaFX application that worked fine on other computers, including Linux Mint even without having JavaFX installed, I could not modified them but I could opened. 我制作了一个JavaFX应用程序,即使没有安装JavaFX,它也可以在其他计算机(包括Linux Mint)上正常运行,我无法修改它们,但可以打开。 Now I am trying to run it on Ubuntu. 现在,我试图在Ubuntu上运行它。 And I get this error: 我得到这个错误:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: Stage
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
    at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: Stage
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more

I have a .pom that looks like this: 我有一个.pom看起来像这样:

<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>moduloDistribuidor</groupId>
  <artifactId>myprogram</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>myProgram</name>
  <url>http://maven.apache.org</url>

    <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>2.9.0</version>
        <type>pom</type>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.9.1</version>
    </dependency>   
    <!-- https://mvnrepository.com/artifact/org.json/json -->
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20180130</version>
    </dependency>
    <dependency>
        <groupId>org.xerial</groupId>
        <artifactId>sqlite-jdbc</artifactId>
        <version>3.21.0.1</version>
    </dependency>

  </dependencies>
</project>

I have tried to add JavaFX in the .pom just in case that was the problem, but it still does not work. 我试图在.pom中添加JavaFX,以防万一这是问题所在,但仍然无法正常工作。

  <build>
        <plugins>
            <plugin>
                <groupId>com.zenjava</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>8.8.3</version>
                <configuration>
                     <mainClass>your.main.class.which.extends.javafx.Application</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>

is what you need to add in your depencies to use java fx . 您需要添加依赖关系才能使用java fx。

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>javafx</artifactId>
    <version>2.2</version>
    <systemPath>${java.home}/lib/ext/jfxrt.jar</systemPath>
    <scope>system</scope>
</dependency>

the error you get is that plugin shouldn' be set at the root of your pom but must be : 您得到的错误是不应将插件设置在pom的根目录,而必须是:

<build>
    <plugins>
        <plugin>
            <groupId>com.zenjava</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>8.8.3</version>
            <configuration>
                <mainClass>your.main.class.which.extends.javafx.Application</mainClass>
            </configuration>
        </plugin>
    </plugins>
</build>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM