Gradle JavaExec complains about not being able to load or find main class

593 views Asked by At

I'm writing a simple Gradle task to launch a java application in my build.gradle file. When I try to run the task with the --info flag, it outputs the java command as follows:

<JAVA_HOME>/bin/java -Xmx256M
   -cp <ABSOLUTE_PATH_TO_ALL_LIBS>/launcherLib/launcherLib.jar:
   <ABSOLUTE_PATH_TO_ALL_LIBS>/lib1/lib1.jar 
   com.hungryTux.launcher.LauncherClass 'launcherArg'

Gradle then complains about not being able to load or find the main class. I know that the com.hungryTux.launcher.LauncherClass class is present in the launcherLib jar file specified in the classpath and has a main method in it. The exact error message is Error: Could not find or load main class.

What's even more amusing is that, if I were to take this command from the Gradle tasks's output and try to run it directly on the terminal, it appears to find the main class and launch the application correctly.

The working directory for this Gradle task is the root of my project containing the build.gradle file. When I try to run the command manually, I do it from the same directory.

I feel I'm missing something obvious with the way JavaExec task works. I've read the documentation for it, but nothing really rings a bell.

I should point out though that the com.hungryTux.launcher.LauncherClass class is not specified as the Main-Class in the META-INF/MANIFEST.MF file contained in the launcherLib.jar file. Could this be an issue? If so, how does this work when run from the command-line?

1

There are 1 answers

0
HungryTux On

This ended up being a parsing issues with one of the jvmArgs I was passing to JavaExec. Getting rid of the offending argument got things working.