我使用的是 spring-boot 版本 1.5.12 和 gradle 5.2.1。
我在我的项目中添加了 Sentry 库,如下所示:
implementation 'io.sentry:sentry:1.7.23'
Gradle 将相关的 jarFile 下载到:\.gradle\caches\modules-2\files-2.1\io.sentry\sentry\1.7.23
我也可以在我的 IDE 中的 External Libraries
部分看到它
然后我在我的本地环境中配置它,一切正常,我可以在 Sentry 仪表板中看到我的异常报告。
但是在那之后,当我想为我的生产环境创建一个版本的项目时,构建操作成功结束,但这个新库不在文件夹中(这是我名为 Distribution
的构建操作的结果)其中包含 myPro.jar 和我使用的其他库,我遇到了异常:
Exception in thread "main" java.lang.NoClassDefFoundError: io/sentry/Sentry
at ir.anarestan.ipc.boot.Boot.initSentry(Boot.java:22)
at ir.anarestan.ipc.boot.Boot.main(Boot.java:17)
Caused by: java.lang.ClassNotFoundException: io.sentry.Sentry
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more
这是我的 build.gradle
文件:
group 'pc-server'
version '0.2.1-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'groovy'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
<some other dependecies>
implementation 'io.sentry:sentry:1.7.23'
}
apply plugin: 'application'
mainClassName = 'ir.anarestan.ipc.boot.Boot'
jar {
manifest {
attributes 'Main-Class': mainClassName,
'Class-Path': configurations.runtime.files.collect {"$it.name"}.join(' ')
}
}
task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File PC',
'Implementation-Version': version,
'Main-Class': 'ir.anarestan.ipc.boot.Boot'
}
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
ext.distributionDir= "${rootDir}/dist/core"
ext.mainClassName = 'ir.anarestan.ipc.boot.Boot'
jar {
manifest {
attributes("Implementation-Title": project.name,
"Implementation-Version": version,
"Main-Class": mainClassName,
"Class-Path": configurations.compile.collect { it.getName() }.join(' '))
}
destinationDir = file("$distributionDir")
}
task copyLibs(type: Copy){
from configurations.compile
into "$distributionDir"
}
task copyConfig(type: Copy){
from "$projectDir/src/main/resources/"
into "$distributionDir"
}
task distribution(dependsOn: ['copyLibs', 'copyConfig', 'jar']){
}
我在这里遇到异常:
@SpringBootApplication
@EnableMongoRepositories(basePackages = {"ir.anarestan.ipc.repository.mongodb"})
public class Boot {
public static void main(String[] args) {
SpringApplication.run(Boot.class, args);
Sentry.init();
}
}
任何帮助将不胜感激,这花了我很多时间!!!