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

how to export a javafx-maven project with firebase

现在我已经在 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

我该如何解决这个错误?

我之前确实遇到过类似的问题,这表明您在 pom.xml:

中缺少一些依赖项
[ERROR]   class file for com.google.cloud.Service not found
[ERROR]   class file for com.google.auth.Credentials not found
[ERROR]   class file for com.google.cloud.Timestamp not found

确保你包括了它们。您可以看到类似的问题 here。 确保在包含依赖项后解决所有冲突,否则你将得到:

Module 'com.example' reads package 'package' from both 'package.example' and 'package.example'

我找到了一种更简单的方法来导出所有依赖项和所有项(包括 firebase)。直接用maven-shape-plugin打包即可。

  1. 添加以下插件到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>
    
  2. 您需要创建另一个 class,其中包含调用主 javafx class 的主函数的主函数,如下所示扩展应用程序。

     public class Launcher {
         public static void main(String[] args) {
             AppInit.main(args);
         }
     }
    
  3. 终于运行mvn clean package