如何使用firebase导出javafx-maven项目 - java

现在,我的项目可以在mvn javafx:run上运行。但是执行mvn javaFx:jlink需要模块描述符。创建模块信息文件后,存在一些与Firebase相关的错误。

部分进口商品进口商品:

import com.google.api.core.ApiFuture;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.firestore.*;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;

在模块信息文件中需要:

requires com.google.api.apicommon;
requires com.google.auth.oauth2;
requires firebase.admin;
requires google.cloud.firestore;

错误:

[ERROR] Failed to execute goal org.openjfx:javafx-maven-plugin:0.0.3:run (default-cli) on project RathnapuraLabs: Error: Unable to execute mojo: Compilation failure: 
[ERROR] /C:/Users/Eshaka/IdeaProjects/RathnapuraLabs/src/main/java/back_end/TestManager.java:[14,35] cannot access com.google.cloud.Service
[ERROR]   class file for com.google.cloud.Service not found
[ERROR] /C:/Users/Eshaka/IdeaProjects/RathnapuraLabs/src/main/java/back_end/DBHandler.java:[69,33] cannot access com.google.auth.Credentials
[ERROR]   class file for com.google.auth.Credentials not found
[ERROR] /C:/Users/Eshaka/IdeaProjects/RathnapuraLabs/src/main/java/back_end/DBHandler.java:[100,85] cannot access com.google.cloud.Timestamp
[ERROR]   class file for com.google.cloud.Timestamp not found

我该如何解决此错误?

参考方案

我想出了一种导出所有依赖项和所有依赖项(包括Firebase)的简便方法。只需使用maven-shape-plugin打包即可。

  • 将以下插件添加到pom.xml
     <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-shade-plugin</artifactId>
         <version>3.0.0</version>
         <executions>
             <execution>
                 <phase>package</phase>
                 <goals>
                     <goal>shade</goal>
                 </goals>
                 <configuration>
                     <transformers>
                         <transformer
                                 implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                             <mainClass>Launcher</mainClass>
                         </transformer>
                     </transformers>
                 </configuration>
             </execution>
         </executions>
     </plugin>
    
  • 您需要使用main创建另一个类,该main调用扩展应用程序的javafx主类的main函数,如下所示。
     public class Launcher {
         public static void main(String[] args) {
             AppInit.main(args);
         }
     }
    
  • 最终运行mvn clean package
  • Java中的<<或>>>是什么意思? - java

    This question already has answers here: Closed 7 years ago. Possible Duplicate: What does >> and >>> mean in Java?我在一些Java代码中遇到了一些陌生的符号,尽管代码可以正确编译和运行,但对于括号在此代码中的作用却感…

    菱形运算符<>是否等于<?> - java

    我在util.TreeSet类中发现,其中一个构造函数正在使用具有空泛型类型的新TreeMap调用另一个构造函数。 public TreeSet(Comparator<? super E> comparator) { this(new TreeMap<>(comparator)); } new TreeMap<>是什么意思…

    与哪些运算符>>兼容 - java

    我这里没有什么代码int b=3; b=b >> 1; System.out.println(b); 它可以完美工作,但是当我将变量b更改为byte,short,float,double时,它包含错误,但是对于变量int和long来说,它可以完美工作,为什么它不能与其他变量一起工作? 参考方案 位移位运算符(例如>>)与任何整数类型兼…

    通过Maven编译器插件不会发生有限的包含和排除 - java

    我正在使用3.6.0版的maven编译器插件,在此我们只想在特定文件夹中编译一个文件,而在该位置编译所有其他文件。例如:在文件夹应用程序中有14个文件,从那我只希望编译1个文件,但它编译了所有文件,如果我要排除,则它也不起作用。 <sourceDirectory>${basedir}/../src/java</sourceDirectory…

    休眠映射<键,设置<值>> - java

    我有以下表格:@Entity @Table(name = "events") Event --id --name @Entity @Table(name = "state") State --id --name @Entity @Table(name = "action") Action --id …