Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create a runnable jar file from command line similar to eclipse

I understood that eclipse generates a runnable jar file with all library .jar files extracted and included in the jar file. How do I do the similar this while creating a jar file manually from command prompt. Do I need to extract all the lib jars into classes folder?

Currently I am using -

    jar cvfm example.jar manifest.txt -C  Classes/ .

Which creates a jar file with all the class files and I need to have all the library jars in the same folder as this example.jar exists.

like image 641
Satya Avatar asked Oct 21 '22 11:10

Satya


1 Answers

there's no way do this kind of thing from the jar command line utility. there are 3 main solutions to the dependencies problem:

  1. in your MANIFEST.MF you may reference other jar files as part of your classpath and then people could invoke your code using java -jar [just your jar] and your dependencies will be picked up
  2. you can package your code and dependencies into a fat jar (which is what youre describing). usually you just convert your project to use some build tool (more advanced than simple javac and jar) and configure the tool. for example with maven. see 2 different approaches here and here
  3. (again with a build tool) you can use something better than a fat jar - use one-jar. the difference is that with a fat jar you run the risk of files with the same name in different libraries "colliding"
like image 100
radai Avatar answered Oct 29 '22 03:10

radai