繁体   English   中英

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

[英]Java jar file won't recognize external libraries added from 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"

终于解决了它,从Sterconium的回答让我在正确的轨道答案 ,但问题是,当我尝试创建它说找不到主类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 dependencies
task 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'
}

暂无
暂无

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

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