Eclipse не использует jar зависимостей gradle во время выполнения или отладки - PullRequest
0 голосов
/ 02 сентября 2018

Я пытаюсь выполнить основную задачу гибернации с помощью проекта Gradle.

Банки зависимостей загружаются Gradle и помещаются в библиотеку Project и External Dependencies.

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()
}

Заранее спасибо !!!

Ответы [ 3 ]

0 голосов
/ 03 апреля 2019

Удалите / прокомментируйте эту зависимость и попробуйте.

runtime group: 'com.oracle.jdbc', name: 'ojdbc6', version: '11.1.0.6.0' 

Мой Build.gradle:

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

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()
}
0 голосов
/ 03 апреля 2019

С помощью плагина eclipse добавляются различные задачи сборки:

./gradlew cleanEclipse eclipse
0 голосов
/ 03 апреля 2019

Я думаю, вы должны обновить classpath с последними изменениями в файле сборки. Eclipse не делает это автоматически во всех версиях. Перейдите в проводник пакетов, щелкните правой кнопкой мыши файл build.gradle, затем в контекстном меню выберите gradle-> refresh gradle project.

Вы также можете включить автоматическую синхронизацию из меню настроек, перейти в Gradle и установить флажок «Автоматическая синхронизация проекта».

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...