我最近将 Grails 项目升级到最新版本,但在启动时遇到以下错误:
|Running application...
Error: Could not find or load main class noverify
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':bootRun'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 9s
以下是我的配置文件:
构建.gradle:
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "https://repo.grails.org/grails/core" }
maven { url "http://repo.grails.org/grails/plugins/" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:$assetPipelineVersion"
}
}
version "1.0.1"
group "com.demo.myapp"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"com.bertramlabs.asset-pipeline"
apply plugin:"org.grails.grails-gsp"
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
maven { url "https://repo.grails.org/grails/core" }
maven { url "http://repo.grails.org/grails/plugins/" }
maven { url "https://dl.bintray.com/animator013/plugins/" }
maven { url "http://dl.bintray.com/uberall/plugins" }
maven { url "http://dl.bintray.com/sachinverma/plugins" }
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-web-boot"
compile "org.grails:grails-logging"
compile "org.grails:grails-plugin-rest"
compile "org.grails:grails-plugin-databinding"
compile "org.grails:grails-plugin-i18n"
compile "org.grails:grails-plugin-services"
compile "org.grails:grails-plugin-url-mappings"
compile "org.grails:grails-plugin-interceptors"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:async"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:events"
compile "org.grails.plugins:hibernate5:${gormVersion-".RELEASE"}"
compile "org.hibernate:hibernate-ehcache"
compile "org.jadira.usertype:usertype.core:6.0.1.GA"
compile "org.grails.plugins:gsp"
compile "org.grails.plugins:grails-spring-websocket:2.5.0.RC1"
console "org.grails:grails-console"
profile "org.grails.profiles:web"
compile "org.postgresql:postgresql:42.2.5" // POSTGRES
compile "net.sf.sociaal:freetts:1.2.2"
runtime "org.glassfish.web:el-impl:2.1.2-b03"
runtime "com.h2database:h2"
runtime "org.apache.tomcat:tomcat-jdbc"
runtime "com.bertramlabs.plugins:asset-pipeline-grails:$assetPipelineVersion"
runtime "org.grails.plugins:database-migration:3.1.0"
compile "org.grails.plugins:grails-shiro:4.3"
compile "org.grails.plugins:audit-logging:3.0.6"
compile "org.grails.plugins:rest:0.8"
compile "org.grails.plugins:scaffolding:4.0.0.RC1"
compile "org.grails.plugins:quartz:2.0.13"
compile 'org.quartz-scheduler:quartz:2.2.1'
testCompile "org.grails:grails-test-mixins:3.3.0"
testCompile "org.grails:grails-gorm-testing-support"
testCompile "org.grails:grails-web-testing-support"
}
tasks.withType(Test) {
systemProperty "geb.env", System.getProperty('geb.env')
systemProperty "geb.build.reportsDir", reporting.file("geb/integrationTest")
systemProperty "webdriver.chrome.driver", System.getProperty('webdriver.chrome.driver')
systemProperty "webdriver.gecko.driver", System.getProperty('webdriver.gecko.driver')
}
assets {
minifyJs = true
minifyCss = true
excludes = ['**/*.less','**/*.mp3','**/*.swf']
enableDigests = true
skipNonDigests = true //set skipNonDigests to true to help reduce the file size of your final generated project.
enableGzip = false //set true to generate gzip named versions of assets
maxThreads = 4
developmentRuntime = true
}
bootRun {
jvmArgs('-Dspring.output.ansi.enabled=always',
'noverify',
'-XX:TieredStopAtLevel=1',
'-Xmx1024m')
sourceResources sourceSets.main
String springProfilesActive = 'spring.profiles.active'
systemProperty springProfilesActive, System.getProperty(springProfilesActive)
}
compileGroovy.groovyOptions.forkOptions.jvmArgs = ['-Xmx1024m']
gradle.属性:
grailsVersion=4.0.5
gormVersion=7.0.4.RELEASE
assetPipelineVersion=3.0.10
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
我尝试了提供的内容Gradle - 无法找到或加载主类但它没有帮助。
知道如何解决这个问题吗?
将你的gradle版本迁移到6.1.1
gradle-wrapper.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
您遇到的错误是由于 build.gradle 文件中的配置不正确造成的。具体来说,问题在于 bootRun 任务配置。以下是修复方法:
打开您的 build.gradle 文件。
找到 bootRun 任务配置。它可能看起来像这样:
bootRun {
jvmArgs = ['-noverify']
}
bootRun {
jvmArgs = ['-Xverify:none']
}
此更改应该可以解决您遇到的“无法找到或加载主类 org.grails.cli.GrailsCli”错误。
此外,值得注意的是,使用“-Xverify:none”会禁用字节码验证,这可能会产生安全隐患。通常建议避免在生产环境中使用它,除非绝对必要。
如果进行此更改后仍然遇到问题,请确保您的 Grails 和 Java 版本兼容,并且您的项目结构正确。
引用: [1] “无法找到或加载主类”是什么意思? [2] 错误:无法找到或加载主类 org.grails.cli.GrailsCli [3] https://rollbar.com/blog/java-could-not-find-or-load-main-class/