繁体   English   中英

使用Gradle导出jar时Firestore依赖项出现问题

[英]Problem with Firestore dependencies while exporting jar using Gradle

我正在使用Gradle在eclipse中构建一个应用程序。 当我通过从Eclipse运行来测试应用程序时,一切都按照它应该的方式工作 - 但是,当我尝试导出并运行.jar文件时,我收到以下错误:

Failed for: .\ServiceAccountKey.json (The system cannot find the file specified)
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/firebase/cloud/FirestoreClient
    at main.Main.getSuroviny(Main.java:105)
    at main.Main.main(Main.java:39)
Caused by: java.lang.ClassNotFoundException:     com.google.firebase.cloud.FirestoreClient
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)

我的build.gradle文件如下所示:

apply plugin: 'java-library'
apply plugin: 'java'

// In this section you declare where to find the dependencies of your project
repositories {
    // Use jcenter for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
    google()
}

dependencies {
    // This dependency is exported to consumers, that is to say found on their compile classpath.
    api 'org.apache.commons:commons-math3:3.6.1'

    // This dependency is used internally, and not exposed to consumers on their     own compile classpath.
    implementation 'com.google.guava:guava:23.0'
    implementation 'com.google.firebase:firebase-admin:5.8.0'
    implementation 'com.google.gms:google-services:4.0.1'

    implementation 'com.google.firebase:firebase-core:16.0.6'
    //dependency for using firebase database
    implementation 'com.google.firebase:firebase-database:16.0.6'
    //dependency for email and password authentication
    implementation 'com.google.firebase:firebase-auth:16.1.0'
    //dependency for cloud storage
    implementation 'com.google.firebase:firebase-storage:16.0.5'
    implementation 'com.google.firebase:firebase-firestore:18.0.0'

    // Use JUnit test framework
    testImplementation 'junit:junit:4.12'
}


// Include dependent libraries in archive.

jar {
  manifest { 
    attributes "Main-Class": "main.Main"
  }  

  from {
    configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
  }
}

我已经仔细检查了所有导入和实现,根据我在Firestore文档中找到的信息,一切似乎都是正确的。

此外,我已经尝试过一些事情,它找到的第一个firstore方法的错误更改 - 无论是DocumentReference,FirestoreClient还是其他任何东西。

感谢任何提前推荐的人。

最后,错误一直是我的错误 - 我的.jar没有包含加载Firestore实例所需的服务密钥(出于某种原因,我希望eclipse在导出runnable jar文件时包含它,因为我检查了“在包“选项中包含资源文件。

因此,我将Service密钥JSON文件包含在我的.jar文件所在的文件夹中,因此我可以根据文件的位置读取它。

这不是一个优雅的解决方法,但就目前而言,这已经足够了。

暂无
暂无

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

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