我正在尝试使用Gradle项目执行基本的休眠任务。
依赖罐由Gradle下载,并放置在项目和外部依赖库中。
我没有任何编译时错误。但是,当我尝试在Eclipse中运行或调试主类时,却发现未找到NoClassDefFoundError类。
Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
当我检查构建路径时,我可以看到依赖项库配置了必需的jar,但eclipse仍未使用它。
但是当我在构建路径中手动添加jar时,没有得到此异常。
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()
}
提前谢谢!
答案 0 :(得分:0)
我认为您应该使用构建文件中的最新更改来更新类路径。 Eclipse不会在所有版本中自动执行此操作。 转到程序包资源管理器,右键单击build.gradle文件,然后从上下文菜单中选择gradle-> refresh gradle项目。
您还可以从首选项菜单启用自动同步,转到gradle,然后选中“自动项目同步”复选框。
答案 1 :(得分:0)
删除/注释此依赖性,然后尝试。
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()
}
答案 2 :(得分:0)
使用eclipse
插件,添加了不同的构建任务:
./gradlew cleanEclipse eclipse