0

I am building fat jar that includes some integration tests that I would like to run from the command line. I would like to be able to do the following:

java -cp myfat.jar org.junit.runner.JUnitCore path.to.MyTest

However, when I do so I get:

Error: Could not find or load main class org.junit.runner.JUnitCore

Now, when I run:

javap -cp myfat.jar org.junit.runner.JUnitCore

I get output that I would expect:

Compiled from "JUnitCore.java"
public class org.junit.runner.JUnitCore {
public org.junit.runner.JUnitCore();
public static void main(java.lang.String...);
...

And my tests run fine when I simply unzip the jar and run something like the following from the directory I unzipped to:

java -cp . org.junit.runner.JUnitCore path.to.MyTest

Why can 'javap' find classes in my jar, but not 'java'? What might I try next to debug this?

user1494672
  • 504
  • 4
  • 10
  • Also, if I grab a junit jar and try the following: `java -cp myfat.jar:junit.jar org.junit.runner.JUnitCore path.to.MyTest` JUnit runs, but then fails because it "Could not find class: path.to.MyTest" So this does seem to be specific to my jar. – user1494672 Nov 06 '18 at 00:36
  • Also, I am using the ShadowJar plugin for Gradle to make my jar. – user1494672 Nov 06 '18 at 00:36
  • 1
    this may help: https://stackoverflow.com/questions/51455197/gradle-fatjar-could-not-find-or-load-main-class – mangusta Nov 06 '18 at 01:32
  • Thanks, mangusta, that was exactly what I was running into. Adding `exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'` to my fat jar task did the trick. Feel free to answer if you'd like. – user1494672 Nov 06 '18 at 15:33

0 Answers0