JavaFX导出和VM参数 [英] JavaFX Export and VM arguments

查看:120
本文介绍了JavaFX导出和VM参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,就是我无法导出JavaFX应用程序.我可以让它与VM参数一起运行(在IDE内部和外部),但这远非最佳选择.我想要一个简单的单击打开"体验.

I have the problem that I just can't export my JavaFX application. I can get it running with the VM arguments (inside the IDE and outside) but that's far from optimal. I want a simple "click to open" experience.

错误:缺少JavaFX运行时组件,并且是运行此应用程序所必需的

Error: JavaFX runtime components are missing, and are required to run this application

我知道可以使用vm参数解决此问题,但是正如我在单击打开"体验之前所说的那样.

I am aware that this problem can be fixed with the vm arguments but as I said before "click to open" experience.

我试图用Maven制作一个胖子罐. (这是我的pom.xml):

I tried to make a fat jar using maven. (Here is my 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>Test</groupId>
  <artifactId>Test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
   <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-base</artifactId>
            <version>11</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>11</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-fxml</artifactId>
            <version>11</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-media</artifactId>
            <version>11</version>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-web</artifactId>
            <version>11</version>
        </dependency>
  </dependencies>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
  <plugins>
       <plugin>
           <artifactId>maven-assembly-plugin</artifactId>
           <version>3.1.1</version>
           <executions>
               <execution>
                   <id>make-jar-with-dependencies</id>
                   <phase>prepare-package</phase>
                   <goals>
                       <goal>single</goal>
                   </goals>
                   <configuration>
                       <archive>
                           <manifest>
                               <mainClass>test.Main</mainClass>
                           </manifest>
                       </archive>
                       <descriptorRefs>
                           <descriptorRef>jar-with-dependencies</descriptorRef>
                       </descriptorRefs>
                   </configuration>
               </execution>
           </executions>
       </plugin>
   </plugins>
 </build>
</project>

我仍然遇到相同的错误,但是导出过程花费的时间比平时更长,这可能是因为JavaFX组件也已导出. 我认为值得一提的是,我在pom.xml中收到了警告

I still get the same error but the export process took way longer than usual probably because the JavaFX components were exported too. I think it is worth mentioning that I get a warning in my pom.xml

为maven-assembly-plugin pom.xml覆盖托管版本2.2-beta-5

Overriding managed version 2.2-beta-5 for maven-assembly-plugin pom.xml

这是我的module-info.java(也许可以帮助解决问题):

Here is my module-info.java (Maybe it helps solving the problem):

module Test {

    requires transitive javafx.controls;
    exports test;

}

推荐答案

好的.经过一番摆弄和一些研究之后,我很高兴地说我终于找到了解决方案.我的Maven问题是我使用Eclipse进行编译,而没有使用Maven进行编译.这是我的项目的最终pom.xml:

Okay. After some fiddling around and some research I am glad to say that I finally found a solution. My problem with maven was that I compiled with eclipse and did not build with maven. So here is my final pom.xml for my project:

<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>Project-Zola</groupId>
  <artifactId>Project-Zola</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <dependencies>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>11</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-graphics </artifactId>
        <version>11</version>
        <classifier>win</classifier>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-graphics</artifactId>
        <version>11</version>
        <classifier>linux</classifier>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-graphics </artifactId>
        <version>11</version>
        <classifier>mac</classifier>
    </dependency>

    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml </artifactId>
        <version>11</version>
        <classifier>win</classifier>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>11</version>
        <classifier>linux</classifier>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml </artifactId>
        <version>11</version>
        <classifier>mac</classifier>
    </dependency>

  </dependencies>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>
        <excludes>
          <exclude>*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <release>12</release>
        </configuration>
      </plugin>
      <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>exec-maven-plugin</artifactId>
         <version>1.6.0</version>
         <executions>
             <execution>
                 <goals>
                     <goal>java</goal>
                 </goals>
             </execution>
         </executions>
         <configuration>
             <mainClass>at.dominik.zola.main.Launcher</mainClass>
         </configuration>
     </plugin>
     <plugin>
         <artifactId>maven-jar-plugin</artifactId>
         <configuration>
             <archive>
                 <manifest>
                     <mainClass>
                         at.dominik.zola.main.Launcher
                     </mainClass>
                 </manifest>
             </archive>
         </configuration>
     </plugin>
     <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-shade-plugin</artifactId>
         <version>3.2.0</version>
         <executions>
             <execution>
                 <phase>package</phase>
                 <goals>
                     <goal>shade</goal>
                 </goals>
                 <configuration>
                     <transformers>
                         <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                             <mainClass>at.dominik.zola.main.Launcher</mainClass>
                         </transformer>
                     </transformers>
                 </configuration>
             </execution>
         </executions>
     </plugin>
    </plugins>
  </build>
</project>

该罐子现在可以执行,我必须给埃里克·内莱斯森(Erik Nellessen)提供道具,因为他已经提交了类似的答案.此pom.xml也是跨平台兼容的.但是要小心,如果您正在使用JavaFX Web组件,则还需要在pom中包括JavaFX Web组件.我通常不建议这样做,因为jar还将包含WebKit组件,并且其大小将增加200mb.感谢所有试图帮助我的人:)

The jar is executable now and I have to give props to Erik Nellessen because he already submitted a similar answer. This pom.xml is also cross-platform compatible. But be careful if you are using the JavaFX web stuff you need to also include the JavaFX web components in the pom. I generally do not recommend that because the jar would then also include WebKit components and its size would increase by like 200mb. Thank's to all the people who tried to help me :)

注意:重要的是您的主类不要扩展Application类,这就是为什么我创建了一个Laucher类的原因,该类只在实际的主类中调用main方法.

NOTE: It is important that your main class does not extend the Application class that's why I created a Laucher class wich just calls the main method in the actual main class.

这篇关于JavaFX导出和VM参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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