Reputation: 2849
I have a simple utility Java program which uses a dependency, which itself has a lot of other dependencies. I need to pack this utility program in an executable jar file. I use Gradle and my JAR task looks like this:
jar {
version = ''
baseName = 'rpc_utility'
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest {
attributes 'Main-Class': 'com.example.rpcclient.MainKt'
}
zip64=true
from { (configurations.compile).collect { it.isDirectory() ? it : zipTree(it) } }
}
This actually does the thing, and I am getting a working JAR file, but it becomes ~60MB. The problem is that in the environment where this jar file suppose to be run, there is another fat jar, which is guarantied to have all the dependencies that this one needs. So if there would be a way, to "tell" my utility jar file, that all the dependencies that it needs are right there, packed in the neighbor jar file, I could make it just a tiny a few kilobytes jar file.
So is there a way to do that? P.S. I googled a lot, and there are similar questions, but non of them seems to be the same as mine.
Upvotes: 0
Views: 931
Reputation: 1786
You can actually define the classpath in your executable jar's manifest. Like this:
manifest {
attributes(
'Main-Class': 'com.example.rpcclient.MainKt',
"Class-Path": "lib/all-dependencies.jar"
)
}
then if you put your all-dependencies.jar file into a directory named "lib" then this should work. Your jar and lib directory should be on the some directory level in this case.
Upvotes: 1