Issue
I have a Gradle project with a good few dependencies, and a fresh server Ubuntu distro. As of now, I'm using Shadow to build a shadowJar, and a deploy this to the server, as dependencies are built in. However, with all of the dependencies the file gets to be rather large, and it's becoming very inconvenient to deploy a huge jar file, when 98% of it doesn't change from build to build. How can I add the dependencies to the server so that I can only send over the normal, much smaller jar file?
As of now when I run the smaller jar file, I get a MySQL warning, and I'm assuming this means that the dependencies are not installed, as connecting to MySQL is the first thing I do in the Main method. Thank you!
Solution
Using gradle we can accomplish this with the jar task
jar {
manifest {
attributes 'Main-Class': 'org.example.Main'
attributes 'Class-Path': configurations.default.files.collect{'lib/' + it.name}.join(' ')
}
}
You can add all of the jars you require to the class path (can use groovy dsl to help here if there are lot). Now on the machine you're deploying to you would have a folder lib relative to your jar with your dependencies.
Answered By - Anthony Cathers
Answer Checked By - Mary Flores (JavaFixing Volunteer)