Reputation: 266
Trying to execute a Corda "fat jar" RPC client that I've built, but it always fails with this error:
Error: Could not find or load main class,
I have confirmed that MANIFEST.MF
contains the correct Main-Class
attribute, and that this class is included inside the jar.
The relevant part of my build.gradle
is:
jar {
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
Executing the jar using java -jar myjar.jar
always produces this error:
Error: Could not find or load main class
Upvotes: 0
Views: 295
Reputation: 266
I have posted this question only for reference because some Corda developers have run into this. The problem with creating a "fat jar" as described above is that some Corda jar artifacts are signed, and so contain extra entries like:
META-INF/CORDACOD.SF
META-INF/CORDACOD.EC
These entries don't apply to the "fat jar" and so if you include them into the "fat jar" then the JVM will reject its classes as invalid when you try to execute it.
The best way to create a "fat jar" in Corda is by using a Gradle plugin like shadow
. However, if you must do this work by hand then you should alter your jar
task accordingly:
jar {
from(configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }) {
exclude "META-INF/*.SF"
exclude "META-INF/*.EC"
exclude "META-INF/*.DSA"
exclude "META-INF/*.RSA"
exclude "META-INF/INDEX.LIST"
}
}
Upvotes: 1