简体   繁体   中英

I can't run the script output by gradle build: "Could not find or load main class"

I have a build.gradle file like:

plugins {
    id 'application'
    ...
}

compileJava {
    options.compilerArgs += ["-Aproject=${project.group}/${project.name}"]
}

application {
    mainClass = 'com.anentropic.myproj.MyProj'
    applicationName = "myproj"  // shell script wrapper name
}

jar {
    archiveBaseName = "myproj"  // jar name
}

It compiles fine when I run gradle build .

There is an artefact output at app/build/scripts/myproj which is a shell script that wraps the invocation of java with my jar file

When I run it I get:

Error: Could not find or load main class com.anentropic.myproj.MyProj
Caused by: java.lang.ClassNotFoundException: com.anentropic.myproj.MyProj

So that's not very useful. How do I fix it?

it won't work from build/scripts folder; the proper way is to unzip the distribution (.zip or.tar) from 'build/distributions/' into a new folder (creates a bin and lib folders) and then run the script from 'bin'

reason - the script (default) is expects the bin and lib structure for resolving paths.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM