1 回答

TA貢獻1846條經(jīng)驗 獲得超7個贊
問題是當我嘗試創(chuàng)建 fatJar 時它說找不到主類,原因是因為我的文件位于 src/test/java 而不是 src /main/java 不知怎的,當我嘗試運行 fatJar 時,它編譯了它,但仍然找不到依賴項,所以我將實現(xiàn)更改為在 build.gradle 文件中編譯,現(xiàn)在它可以工作了。所以這是我的最終 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'
}
添加回答
舉報