How to create jar executable from command line similar to eclipse

I realized that eclipse generates a jar executable with all the .jar library files extracted and included in the jar file. How to do this when creating a jar file manually from the command line. Do I need to extract all lib libraries to the class folder?

I am currently 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 banks of the library in the same folder as this example.jar.

+4
source share
1 answer

there is no way to do this from the jar command line utility. There are 3 main solutions to the dependency problem:

  • in your MANIFEST.MF file, you can reference other jar files as part of your class path, and then people can call your code with java -jar [just your jar] and your dependencies will be found
  • you can pack your code and dependencies in a thick jar (this is what you describe). usually you just convert your project to use some kind of build tool (more advanced than simple javac and jar) and customize the tool. for example with maven . see 2 different approaches here and here
  • (again using the build tool) you can use something better than a fat jar - use one-jar . the difference is that when using a thick jar, you run the risk of having files with the same name in different colliding libraries
+3
source

All Articles