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

duanxz 阅读:17 2024-12-31 21:38:35 评论:0

现在我已经让我的项目在 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> 
    
  • 您需要创建另一个主类,该主类调用扩展应用程序的主 javafx 类的 main 函数,如下所示。
     public class Launcher { 
         public static void main(String[] args) { 
             AppInit.main(args); 
         } 
     } 
    
  • 终于跑了mvn clean package

  • 标签:Maven
    声明

    1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

    关注我们

    一个IT知识分享的公众号