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

Time:12-22

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?

CodePudding user response:

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.

  • Related