Search code examples
javaeclipsebatch-filegradlebuildship

Gradle creates broken start scripts. How to fix?


I am trying to learn how to build applications using Gradle; to do this I use the 'Application' plug in. This plug in builds executable scripts that runs my jar file. However the batch file that is generated is showing an error. This is for every project I build with Gradle.

I can execute the jar file fine using 'java -jar app.jar' but the app.bat file only shows the error.

The error shows is; Error: Could not find or load main class com.test.Main

I have exhausted my ability to search stackoverflow and google for a solution. It seems possible that there is an error with the %CLASSPATH%?

Note: I had the batch file for an early project working perfectly fine. When revisiting the project later in the day (no code changed) the batch file fails to run. This makes me thing there is a setting/ environment issue more than a programmatic one?


Solution

  • I needed to use the assembleDist task to create a zip folder. This zip folder contained the sh and batch files with the correct classpaths and worked perfectly.

    Note: The sh and batch files located in /scripts are used by Gradle to run the application during development. When trying to execute them from the terminal or command prompt they could not find the main class or the libraries used. As far as I can tell this was due to the %CLASSPATH% not being tailored for use outside of gradle.

    Running the distribution task creates an archive of the project containing all of the required files and working execution scripts. These were the files I should have been testing, not those found in the gradle project.