Eclipse 在运行或调试期间不使用 gradle dependencies jar

标签 eclipse gradle

我正在尝试使用 Gradle 项目执行基本的休眠任务。

依赖 jar 由 Gradle 下载并放置在项目和外部依赖库中。

enter image description here

我没有收到任何编译时错误。但是当我尝试在 Eclipse 中运行或调试主类时,我得到类未找到 NoClassDefFoundError。

Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration

当我检查构建路径时,我可以看到依赖库配置了所需的 jar,但 eclipse 仍然没有使用它。

enter image description here

但是当我在构建路径中手动添加 jar 时,我没有收到此异常。

enter image description here

Build.gradle 文件

plugins {
    // Apply the java-library plugin to add support for Java Library
    id 'java-library'
}

apply plugin: "eclipse"

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:23.0'

    // Use JUnit test framework
    testImplementation 'junit:junit:4.12'

    // https://mvnrepository.com/artifact/org.hibernate/hibernate-core
    compile group: 'org.hibernate', name: 'hibernate-core', version: '5.3.6.Final'

    // https://mvnrepository.com/artifact/com.oracle.jdbc/ojdbc6
    runtime group: 'com.oracle.jdbc', name: 'ojdbc6', version: '11.1.0.6.0'

    // https://mvnrepository.com/artifact/com.oracle/ojdbc6
    runtime group: 'com.oracle', name: 'ojdbc6', version: '11.2.0.4.0-atlassian-hosted'




}

// In this section you declare where to find the dependencies of your project
repositories {
    // Use jcenter for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
    mavenCentral()
}

提前致谢!!!

最佳答案

我认为您应该使用构建文件中的最新更改来更新类路径。 Eclipse 不会在所有版本中自动执行此操作。 转到 package explorer,右键单击 build.gradle 文件,然后从上下文菜单中选择 gradle->refresh gradle project。

您还可以从首选项菜单启用自动同步,转到 gradle,然后选中“自动项目同步”复选框。

关于Eclipse 在运行或调试期间不使用 gradle dependencies jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52133487/

相关文章:

java - IWAB0399E 从 WSDL 生成 Java 时出错 : java. io.IOException : Type {http://www. w3.org/2001/XMLSchema}array 被引用但未定义

java - SAP JBOSS 的 jar 问题

Gradle ShadowJar 与其他 SourceSet 资源

android-studio - Libgdx:使用操作系统独立路径 'libgdx-freetype.dylib'找到了多个文件

Android Studio 0.3.1、appcompat-v7 和 android 库项目总是生成 IllegalStateException

python - PYTHONPATH 中 PyDev 项目引用、源文件夹和外部库的顺序是什么

Java泛型类型推导错误

java - System.out.println() 快捷方式不起作用

grails - Grails 3.0可搜索插件

更新后 android.support 库不兼容