Java jar 文件无法识别从 gradle 添加的外部库

各位,基本上我在 java 项目中使用 gradle,并且无法导出我正在使用的 jar 文件中的库。尝试了一些解决方案但没有任何效果。你知道我在 gradle 文件中缺少什么吗?或者我在导出时需要指定一些内容。我正在使用 Eclipse


谢谢,这是我的 gradle 文件


    enter code here

plugins {

    // Apply the java-library plugin to add support for Java Library

    id 'java-library'


}


repositories {

    // Use jcenter for resolving your dependencies.

    // You can declare any Maven/Ivy/file repository here.

    jcenter()

    mavenCentral()

}


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:27.0.1-jre'


    // Use JUnit test framework

    testImplementation 'junit:junit:4.12'


    implementation "redis.clients:jedis:3.0.1"

    implementation  'org.pixsee.java-fcm:Java-fcm:1.0.0'  


    implementation 'com.google.firebase:firebase-admin:6.10.0'



    compile "org.slf4j:slf4j-api:1.6.1"


     implementation 'org.slf4j:slf4j-simple:1.7.25'

     implementation "com.google.maps:google-maps-services:0.9.4"

     implementation 'io.vertx:vertx-core:3.8.1'


}

sourceCompatibility = 1.8

version = '1.0'

jar {

    manifest {

        attributes 'Implementation-Title': 'GeofenceServer',

                   'Implementation-Version': version

    }

}

apply plugin: "eclipse"


暮色呼如
浏览 81回答 1
1回答

喵喵时光机

问题是当我尝试创建 fatJar 时它说找不到主类,原因是因为我的文件位于 src/test/java 而不是 src /main/java 不知怎的,当我尝试运行 fatJar 时,它编译了它,但仍然找不到依赖项,所以我将实现更改为在 build.gradle 文件中编译,现在它可以工作了。所以这是我的最终 build.gradle 文件如何看起来像 。    /* * This file was generated by the Gradle 'init' task. * * This generated file contains a sample Java Library project to get you started. * For more details take a look at the Java Libraries chapter in the Gradle * User Manual available at https://docs.gradle.org/5.4/userguide/java_library_plugin.html */plugins {    // Apply the java-library plugin to add support for Java Library    id 'java-library'}repositories {    // Use jcenter for resolving your dependencies.    // You can declare any Maven/Ivy/file repository here.    jcenter()    mavenCentral()}apply plugin: "java"apply plugin: "eclipse"version = '1.0'//create a single Jar with all dependenciestask fatJar(type: Jar) {    manifest {        attributes 'Implementation-Title': 'Gradle Jar File Example',             'Implementation-Version': version,            'Main-Class': 'Server.Test'    }    baseName = project.name + '-all'    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }    with jar}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:27.0.1-jre'    // Use JUnit test framework    testImplementation 'junit:junit:4.12'    implementation "redis.clients:jedis:3.0.1"    implementation 'com.google.firebase:firebase-admin:6.10.0'    implementation 'org.slf4j:slf4j-simple:1.7.25'    implementation 'com.google.maps:google-maps-services:0.10.0'    compile 'io.vertx:vertx-core:3.8.1'    implementation 'com.google.code.gson:gson:2.8.5'}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java