gpt4 book ai didi

java - 使用 gradle 处理 asm 依赖项时出现 NoClassDefFoundError

转载 作者:太空宇宙 更新时间:2023-11-04 13:04:20 25 4
gpt4 key购买 nike

当我尝试使用 gradle 使用 asm 包构建程序时,出现以下错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
at analysis.CCMetric.main(CCMetric.java:5)
Caused by: java.lang.ClassNotFoundException:org.objectweb.asm.ClassVisitor
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)
... 1 more

我的gradle脚本如下:

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'application'

mainClassName = 'analysis.CCMetric'

repositories {
maven { url "http://repo.maven.apache.org/maven2" }
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

dependencies {
compile 'org.ow2.asm:asm-all:5.0.2'
compile 'commons-io:commons-io:2.4'
compile 'org.jgrapht:jgrapht-core:0.9.1'
compile 'asm:asm:3.3.1'
}

jar {
manifest {
attributes 'Main-Class': 'analysis.CCMetric'
}
baseName = 'CCMetric'
version = '1.0.0'
}

task wrapper(type: Wrapper) {
gradleVersion = '2.9'
}

我使用 gradle build 来构建项目,并使用 java -jar build/libs/CCMetric.jar 运行 jar 文件,然后得到了上述异常。

最佳答案

我从 Gradle 论坛找到了解决方案。现在我粘贴 Muschko, B 的答案。

You will also have to provide the external JARs you are depending on when executing the Java command. Gradle does not hook into the Java command magically and provide the external libraries. A good alternatively you can look into is the Application plugin which does something you are looking for out-of-the-box with the run task.

关于java - 使用 gradle 处理 asm 依赖项时出现 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34643391/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com