{"id":19065633,"url":"https://github.com/caiorss/build-fat-jar","last_synced_at":"2026-05-15T07:30:16.620Z","repository":{"id":90042920,"uuid":"96239734","full_name":"caiorss/build-fat-jar","owner":"caiorss","description":"Unix Shell Script to build java/Scala fat-jars and make the distributions and deployment of Scala applications easier.","archived":false,"fork":false,"pushed_at":"2017-08-20T03:37:24.000Z","size":92,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-02T14:15:22.066Z","etag":null,"topics":["bash","deploy","fat-jar","fatjar","jar","java","scala","script","shell","tool","unix","utility"],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/caiorss.png","metadata":{"files":{"readme":"README.org","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-04T17:17:15.000Z","updated_at":"2024-06-17T03:40:31.000Z","dependencies_parsed_at":"2024-04-21T02:32:57.017Z","dependency_job_id":null,"html_url":"https://github.com/caiorss/build-fat-jar","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caiorss%2Fbuild-fat-jar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caiorss%2Fbuild-fat-jar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caiorss%2Fbuild-fat-jar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/caiorss%2Fbuild-fat-jar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/caiorss","download_url":"https://codeload.github.com/caiorss/build-fat-jar/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240118431,"owners_count":19750491,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","deploy","fat-jar","fatjar","jar","java","scala","script","shell","tool","unix","utility"],"created_at":"2024-11-09T00:51:43.836Z","updated_at":"2026-05-15T07:30:16.532Z","avatar_url":"https://github.com/caiorss.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"#+TITLE: jar-tools.sh - Unix Shell Script to build java/Scala fat-jars\n#+AUTHOR: Caio Rodrigues\n#+STARTUP: showall\n#+KEYWORDS: unix shell script java scala fatjar fat-jar deploy dependency\n\n* jart-tools.sh\n** Overview\n\njart-tools is a Unix shell script to build fat-jars from scala\napplications It means build a single and self-contained jar file with\nthe underlying application, all dependencies and scala runt-time\nlibraries.\n\nMotivation: It makes the distribution of java and scala libraries\neasier as the user only needs to run =$ java -jar application.jar= or\ndouble click at the application.jar file. The developer also doesn't\nneed to build any shell script to run the jar file.\n\nBenefits:\n\n - Inspect jar files.\n\n - Bundle a java/scala application with all its dependencies.\n\n - Make the deployment and distribution easy and simple.\n\n - Run Scala application in a machine without Scala installed.\n\n - Run a Scala/java application with a simple double click.\n\n** Install\n\nJust copy the script _jart-tools.sh_ to any directory listed in the\n$PATH variable.\n\nNo dependencies are required. It only needs java and scala available.\n\nDownload it:\n\n#+BEGIN_SRC sh\n  cd ~/bin\n  $ curl -O -L https://github.com/caiorss/jart-tools/raw/master/jar-tools.sh\n  $ chmod +x jar-tools.sh\n\n  $ ./jar-tools.sh\n#+END_SRC\n\n** Usage and Examples\n*** Show user help\n\n + =./jart-tools.sh=\n\n#+BEGIN_SRC text\n$ jar-tools.sh \nBuild fat jar. Tool like one-jar to build java fat jar.\n\nOptions:\n\n + Show information about Scala libraries.\n\n    * ./jar-tools.sh -scala-lib\n\n + Run an application compiled with Scala using its runtime.\n\n   * ./jar-tools.sh -scala-run scalaApp.jar\n\n + Start scala repl loading all *.jar files in classpath from ./lib\n\n   * ./jar-tools.sh -scala-repl\n\n + Build a fat jar for a Scala application. out/output-jar.jar. The\n main-jar file contains the main class.\n\n   * ./jar-tools.sh -scala-build-jar out/output-jar.jar main-jar.jar lib/dependency1.jar lib/dependency2.jar\n\n\n + Display manifest of a jar file.\n\n   * ./jar-tools.sh -jar-mainifest file.jar\n\n + Display main class of a jar file.\n\n   * ./jar-tools.sh -jar-main file.jar\n\n + View contents of a jar file\n\n   * ./jar-tools.sh -jar-view file.jar\n\n + Make a self-executable jar-file.sh out of jar-file.jar \n   that can be run as ./jar-file.sh instead of '$ java -jar jar-file.jar.'\n\n   * ./jar-tools.sh -jar-to-sh file.jar\n\n + Makes a self-executable jar file with .sh extension out of a scala\n   compiled jar file. It assumes that scala is instaled in the target machine. \n   The generated file, app.sh that can be run as ./app.sh instead of '$ java -jar app.sh'\n\n   *  ./jar-tools.sh -jar-to-sh2 file.jar\n\nNote: Use the command below to enable debug.\n\n      $ env DEBUG=true ./build-fat-jar.sh\n\n#+END_SRC\n\n*** Show scala libraries location\n\n + =./jart-tools.sh -scala-lib=\n\n#+BEGIN_SRC sh\n$ jart-tools.sh -scala-lib\nScala library path = /home/archbox/opt/scala-2.11.8/lib\n\n/home/archbox/opt/scala-2.11.8/lib/akka-actor_2.11-2.3.10.jar\n/home/archbox/opt/scala-2.11.8/lib/config-1.2.1.jar\n/home/archbox/opt/scala-2.11.8/lib/jline-2.12.1.jar\n/home/archbox/opt/scala-2.11.8/lib/scala-actors-2.11.0.jar\n/home/archbox/opt/scala-2.11.8/lib/scala-actors-migration_2.11-1.1.0.jar\n/home/archbox/opt/scala-2.11.8/lib/scala-compiler.jar\n/home/archbox/opt/scala-2.11.8/lib/scala-continuations-library_2.11-1.0.2.jar\n/home/archbox/opt/scala-2.11.8/lib/scala-continuations-plugin_2.11.8-1.0.2.jar\n/home/archbox/opt/scala-2.11.8/lib/scala-library.jar\n/home/archbox/opt/scala-2.11.8/lib/scalap-2.11.8.jar\n/home/archbox/opt/scala-2.11.8/lib/scala-parser-combinators_2.11-1.0.4.jar\n/home/archbox/opt/scala-2.11.8/lib/scala-reflect.jar\n/home/archbox/opt/scala-2.11.8/lib/scala-swing_2.11-1.0.2.jar\n/home/archbox/opt/scala-2.11.8/lib/scala-xml_2.11-1.0.4.jar\n\n#+END_SRC\n\n*** Inspect Jar files \n**** Show manifest file \n\nExample:\n\n - =$ jar-tools.sh -jar-manifest canvas.jar=\n\n#+BEGIN_SRC sh \n$ jar-tools.sh -jar-manifest canvas.jar \nManifest-Version: 1.0\nScala-Compiler-Version: 2.11.8\nMain-Class: Main\n#+END_SRC\n\n**** Show contents \n\n + =$ jar-tools.sh -jar-view canvas.jar=\n\n#+BEGIN_SRC sh \n$ jar-tools.sh -jar-view canvas.jar \n    75 Fri Jul 21 18:35:46 BRT 2017 META-INF/MANIFEST.MF\n  1773 Fri Jul 21 18:35:46 BRT 2017 Main$$anon$2$OriginXY$.class\n  2930 Fri Jul 21 18:35:46 BRT 2017 Main$$anon$2$OriginXY.class\n   626 Fri Jul 21 18:35:46 BRT 2017 Main$$anon$2$OriginType.class\n  1755 Fri Jul 21 18:35:46 BRT 2017 Main$$anon$2$OriginC$.class\n  1759 Fri Jul 21 18:35:46 BRT 2017 Main$$anon$2$OriginBL$.class\n  1894 Fri Jul 21 18:35:46 BRT 2017 Main$$anon$2$DrawUtils$$anonfun$withContext$1.class\n  1682 Fri Jul 21 18:35:46 BRT 2017 Main$$anon$2$DrawUtils$$anonfun$withColor$1$$anonfun$apply$4.class\n  1654 Fri Jul 21 18:35:46 BRT 2017 Main$$anon$2$DrawUtils$$anonfun$withColor$1.class\n     ... ... ... \n#+END_SRC\n\n*** Make a self-executable jar file \n\nIt generates a self-executable jar-file with '.sh' extension of unix\nshell script from a runnable jar file named app.jar which can be\nexecuted with:\n\n - =$ java -jar app.jar= \n\nThe application can be executed with ./app.sh.\n\n1. Run \n\n#+BEGIN_SRC sh \n$ jar-tools.sh -jar-to-sh out/linuxPanel.jar\nBuild jar-executable out/linuxPanel.sh\nRun it with ./out/linuxPanel.sh\n#+END_SRC\n\n2. The command above generates linuxPanel.sh that can be executed with: \n\n#+BEGIN_SRC sh \n./linuxPanel.sh\n#+END_SRC\n\n*** Make a self-executable jar file without scala-library bundled\n\nThis command builds a self-executable jar-file out of a scala-compiled\njar file that cannot be run with 'java -jar' directly, but can be run\nwith 'scala app.jar'. \n\nExample: \n\n1. Build the program linuxPanel.jar \n\n#+BEGIN_SRC sh\n$ scalac linuxPanel.scala -d linuxPanel.jar\n#+END_SRC\n\n2. Build the self-executable jar, named linuxPanel.sh. \n\n#+BEGIN_SRC sh \n$ jar-tools.sh -jar-to-sh2 linuxPanel.jar \nInput      = linuxPanel.jar\nOutput     = linuxPanel.sh\nMain class =  linuxPanel.Main\nBuild jar-executable linuxPanel.sh\nRun it with ./linuxPanel.sh\n#+END_SRC\n\n3. Run the application linuxPanel.sh \n\n#+BEGIN_SRC sh \n./linuxPanel.sh \n#+END_SRC\n\n4. Optional - Check linuxPanel.sh \n\n#+BEGIN_SRC sh \n$ file linuxPanel.sh \nlinuxPanel.sh: a /usr/bin/env sh script executable (binary data)\n\n\n$ head -n 15 linuxPanel.sh \n#!/usr/bin/env sh\n\n# set -x\n\nSCALA_LIB_PATH=\"$(dirname $(dirname $(which scala)))\"/lib\n\njars=\"\"\nfor f in $(ls $SCALA_LIB_PATH); do\n    jars=$SCALA_LIB_PATH/$f:$jars\ndone\njars=$jars\".\"\n\njava -cp $jars:$0  linuxPanel.Main\n\nexit 0\n#+END_SRC\n\n*** Build a fat jar for a scala application\n**** Overview\n + =./jart-tools.sh -scala out/output-jar.jar main-jar.jar dep1.jar dep2.jar ...=\n\nBuild a fat jar for the application main-jar.jar that contains the\nmain class packing it with the scala run-time (scala-library.jar) and\nthe jar dependencies dep1.jar dep2.jar and so on.\n**** Example 1\n\nIt will build a fat-jar for the sample-scala program [[file:testProgram.scala][file:testProgram.scala]]\n\n1. Compile the scala program to a jar file.\n\n#+BEGIN_SRC sh\n$ scalac testProgram.scala -d testProgram.jar\n#+END_SRC\n\nRun it with scala:\n\n#+BEGIN_SRC sh\n$ scala testProgram.jar\nHello world Scala\n\n#+END_SRC\n\nIt will display a simple GUI:\n\n[[file:images/program-screenshot.png][file:images/program-screenshot.png]]\n\nRun it with java: It first will fail because the dependency\nscala-library.jar is missing.\n\n#+BEGIN_SRC sh\n$ java -cp testProgram.jar scalaApp.Main\nException in thread \"main\" java.lang.NoClassDefFoundError: scala/Predef$\n\tat scalaApp.Main$.main(testProgram.scala:8)\n\tat scalaApp.Main.main(testProgram.scala)\nCaused by: java.lang.ClassNotFoundException: scala.Predef$\n\tat java.net.URLClassLoader$1.run(URLClassLoader.java:372)\n\tat java.net.URLClassLoader$1.run(URLClassLoader.java:361)\n\tat java.security.AccessController.doPrivileged(Native Method)\n\tat java.net.URLClassLoader.findClass(URLClassLoader.java:360)\n\tat java.lang.ClassLoader.loadClass(ClassLoader.java:424)\n\tat sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)\n\tat java.lang.ClassLoader.loadClass(ClassLoader.java:357)\n\t... 2 more\n\n$ java -jar testProgram.jar\nException in thread \"main\" java.lang.NoClassDefFoundError: scala/Predef$\n\tat scalaApp.Main$.main(testProgram.scala:8)\n\tat scalaApp.Main.main(testProgram.scala)\nCaused by: java.lang.ClassNotFoundException: scala.Predef$\n\tat java.net.URLClassLoader$1.run(URLClassLoader.java:372)\n\tat java.net.URLClassLoader$1.run(URLClassLoader.java:361)\n\tat java.security.AccessController.doPrivileged(Native Method)\n\tat java.net.URLClassLoader.findClass(URLClassLoader.java:360)\n\tat java.lang.ClassLoader.loadClass(ClassLoader.java:424)\n\tat sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)\n\tat java.lang.ClassLoader.loadClass(ClassLoader.java:357)\n\t... 2 more\n\n#+END_SRC\n\nTry again. Now it works.\n\n#+BEGIN_SRC scala\n$ java -cp /home/archbox/opt/scala-2.11.8/lib/scala-library.jar:testProgram.jar  scalaApp.Main\nHello world Scala\n\n#+END_SRC\n\n*2. Build a fat jar.*\n\nIt will create the file testProgram-fat.jar.\n\n#+BEGIN_SRC sh\n$ ./jar-tools.sh -scala-build-jar testProgram-fat.jar testProgram.jar\nAt directory /home/archbox/Documents/projects/jart-tools.sh/temp\n\nManifest Content META-INF/MANIFEST.MF\n\nManifest-Version: 1.0\nScala-Compiler-Version: 2.11.8\nMain-Class: scalaApp.Main\n\nBuilding fat-jar file ...\nadded manifest\nadding: library.properties(in = 187) (out= 135)(deflated 27%)\nignoring entry META-INF/\nignoring entry META-INF/MANIFEST.MF\nadding: rootdoc.txt(in = 4279) (out= 1329)(deflated 68%)\nadding: scala/(in = 0) (out= 0)(stored 0%)\nadding: scala/languageFeature.class(in = 2317) (out= 1471)(deflated 36%)\nadding: scala/Function6.class(in = 1739) (out= 1012)(deflated 41%)\n\n.... ... ... ... .... .... ... ... ... .... .... ... ... ... ....\n\nadding: scala/Function1.class(in = 2600) (out= 1431)(deflated 44%)\nadding: scala/Function2$mcFJI$sp.class(in = 323) (out= 195)(deflated 39%)\nadding: scala/Tuple3$.class(in = 1555) (out= 720)(deflated 53%)\nadding: scala/Unit.class(in = 1133) (out= 809)(deflated 28%)\nadding: scala/Function21.class(in = 3610) (out= 1671)(deflated 53%)\nadding: scala/Enumeration$$anonfun$scala$Enumeration$$isValDef$1$1.class(in = 1771) (out= 890)(deflated 49%)\nadding: scala/Function7.class(in = 1851) (out= 1055)(deflated 43%)\nadding: scala/Function18$$anonfun$tupled$1.class(in = 2393) (out= 1019)(deflated 57%)\nadding: scala/Predef$StringFormat$.class(in = 2107) (out= 1010)(deflated 52%)\nadding: scala/Tuple5$.class(in = 1805) (out= 768)(deflated 57%)\nadding: scala/Function2$mcZJD$sp.class(in = 323) (out= 196)(deflated 39%)\nadding: scala/Char.class(in = 6084) (out= 3604)(deflated 40%)\nadding: scala/Float.class(in = 5382) (out= 3268)(deflated 39%)\nadding: scala/Enumeration$ValueSet$$anon$2.class(in = 1673) (out= 668)(deflated 60%)\nadding: scalaApp/(in = 0) (out= 0)(stored 0%)\nadding: scalaApp/Main.class(in = 585) (out= 472)(deflated 19%)\nadding: scalaApp/Main$.class(in = 1386) (out= 830)(deflated 40%)\n--------------------------------------\n\nBuilt file: testProgram-fat.jar Ok.\n\n#+END_SRC\n\n*3. Check the generated file*\n\n#+BEGIN_SRC sh\n  $ file testProgram-fat.jar\n  testProgram-fat.jar: Java archive data (JAR)\n\n  # A little bit heavier, but this size is insignificant and a very\n  # small price for all Scala's goodness.\n  #\n  $ du -h testProgram-fat.jar\n  5,5M    testProgram-fat.jar\n  5,5M    total\n\n  $ jar -tf testProgram-fat.jar\n  META-INF/\n  META-INF/MANIFEST.MF\n  library.properties\n  rootdoc.txt\n  scala/\n  scala/languageFeature.class\n  scala/Function6.class\n  scala/Function2$mcIDI$sp.class\n  scala/Function1$mcDI$sp.class\n  scala/Product2.class\n  scala/SerialVersionUID.class\n  scala/Function1$mcVI$sp$class.class\n  scala/Function22$class.class\n  ... ... ... ... ... ....\n\n  scala/Float.class\n  scala/Enumeration$ValueSet$$anon$2.class\n  scalaApp/\n  scalaApp/Main.class\n  scalaApp/Main$.class\n\n#+END_SRC\n\n\n*4. Run it and deploy.*\n\nThe fat jar can be run with a simple command =java -jar= or by double\nclicking it if the desktop is configured properly. It can also be\ndistributed to machines without Scala installed.\n\n#+BEGIN_SRC sh\n$ java -jar testProgram-fat.jar\nHello world Scala\n#+END_SRC\n\n**** Example 2\n\nExample: It will build the fat-jar file out/exrates.jar from the\napplication bin/demoTableExrates.jar and pack it with\n_scala-library.jar_ and _scala-xml_2.11-1.0.4.jar_.\n\n#+BEGIN_SRC sh\n  $ jar-tools.sh -scala out/exrates.jar \\\n    bin/demoTableExrates.jar \\\n    bin/jswing.jar /home/archbox/opt/scala-2.11.8/lib/scala-xml_2.11-1.0.4.jar\n\n  # Script output below\n  At directory /home/archbox/Documents/projects/jswing.scala/out/temp\n  Extracting /home/archbox/Documents/projects/jswing.scala/bin/jswing.jar\n  Extracting /home/archbox/Documents/projects/jswing.scala/bin/jswing.jar\n\n  Manifest Content META-INF/MANIFEST.MF\n\n  Manifest-Version: 1.0\n  Scala-Compiler-Version: 2.11.8\n  Main-Class: Main\n\n  added manifest\n  adding: jswing/(in = 0) (out= 0)(stored 0%)\n  adding: jswing/Event$$anon$1.class(in = 790) (out= 459)(deflated 41%)\n  adding: jswing/Dialog$FileChooser$$anonfun$run$1.class(in = 1179) (out= 613)(deflated 48%)\n  adding: jswing/JUtils$.class(in = 1984) (out= 1071)(deflated 46%)\n  adding: jswing/guis/(in = 0) (out= 0)(stored 0%)\n  adding: jswing/guis/TextView.class(in = 5485) (out= 3114)(deflated 43%)\n  adding: jswing/guis/PictureFrame$.class(in = 1114) (out= 561)(deflated 49%)\n  adding: jswing/guis/ListView.class(in = 6373) (out= 3410)(deflated 46%)\n  adding: jswing/guis/PictureFrame.class(in = 4352) (out= 2510)(deflated 42%)\n  adding: jswing/guis/ListView$.class(in = 859) (out= 456)(deflated 46%)\n  adding: jswing/guis/ListView$$anon$1.class(in = 1047) (out= 584)(deflated 44%)\n  adding: jswing/guis/ListView$$anonfun$onSelect$1.class(in = 1398) (out= 728)(deflated 47%)\n\n  ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...\n\n  adding: scala/Predef$StringFormat$.class(in = 2107) (out= 1010)(deflated 52%)\n  adding: scala/Tuple5$.class(in = 1805) (out= 768)(deflated 57%)\n  adding: scala/Function2$mcZJD$sp.class(in = 323) (out= 196)(deflated 39%)\n  adding: scala/Char.class(in = 6084) (out= 3604)(deflated 40%)\n  adding: scala/Float.class(in = 5382) (out= 3268)(deflated 39%)\n  adding: scala/Enumeration$ValueSet$$anon$2.class(in = 1673) (out= 668)(deflated 60%)\n  adding: scala-xml.properties(in = 112) (out= 76)(deflated 32%)\n  --------------------------------------\n\n  Built file: out/exrates.jar Ok.\n  Run it with $ java -jar out/exrates.jar\n\n#+END_SRC\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaiorss%2Fbuild-fat-jar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcaiorss%2Fbuild-fat-jar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcaiorss%2Fbuild-fat-jar/lists"}