Jarget is a command line application to download java libraries or jar files from Maven Central in a easy and fast way without the need to set up a project. It is useful to experiment java libraries with languages hosted in JVM such as Jython (Python implemented in Java), Scala or Clojure.
Features:
- Download Scala and Java libraries from https://mvnrepository.com/ without creating a project. It is useful for quick experiments and library evaluation.
- Display information about Java packages.
- Start Scala with all jar files from directory loaded in Classpath.
- Run scala compiler with all jars from some directory in classpath.
- Parallallel download of dependencies.
- Inspect and extract data from jar files.
- Show MANIFEST
- Display files
- Show assets
- Extract files
- Build uber jar, jar file bundled with all dependencies making deployment and distribution easier.
- Build self-exectutable *nix uber jar file that can be run with ./application
Evaluation of Scala cats library, based on Scala Cats library for dummies — part 1
Jarget allows evaluation of Scala libraries without the need to create a project or complicated Maven directory structure.
Instead of creating a SBT project with:
libraryDependencies += "org.typelevel" %% "cats" % "0.7.2"
It is possible to:
- Get information about the library. Note: 2.11 is the Scala version.
$ jarget mvn-show org.typelevel/cats_2.11/0.7.2
Package: catsJVM
Packaging: jar
Coordinates[1]: group = org.typelevel artifact = cats_2.11 version = 0.7.2
Coordinates[2]: org.typelevel/cats_2.11/0.7.2
Url: https://github.com/typelevel/cats
Description: catsJVM
Dependencies:
- org.scala-lang/scala-library/2.11.8
- org.typelevel/cats-macros_2.11/0.7.2
- org.typelevel/cats-kernel_2.11/0.7.2
- org.typelevel/cats-kernel-laws_2.11/0.7.2
- org.typelevel/cats-core_2.11/0.7.2
- org.typelevel/cats-laws_2.11/0.7.2
- org.typelevel/cats-free_2.11/0.7.2
- org.typelevel/cats-jvm_2.11/0.7.2
- com.github.mpilquist/simulacrum_2.11/0.8.0
- org.typelevel/machinist_2.11/0.4.1
- Install it and run with:
Load Scala REPL with all jars from ./lib in classpath and test the package:
$ jarget exec -p=org.typelevel/cats-core_2.12/0.9.0 -- scala
Welcome to Scala 2.12.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_144).
Type in expressions for evaluation. Or try :help.
scala>
scala> import cats._, cats.instances.all._
import cats._
import cats.instances.all._
scala> val len: String => Int = _.length
len: String => Int = $$Lambda$1089/1057262726@255d9277
scala> Functor[List].map(List("scala", "cats")) (len)
res0: List[Int] = List(5, 4)
scala>
- [ ] - Add search in console feature.
- [X] - Add search in browser feature.
- [X] - Add package cache
- [ ] - Show all versions of a given package available in the repository.
- [ ] - Support multiple repositories.
- [ ] - Support project configuration file.
- [X] - Improve command line handling
- [X] - Improve error handling.
- [X] - Feature to make Uber Jar
- [X] - Shrink the generated uber jar using Pro-guard.
- [X] - Create a Windows exe wrapper
- [X] - Crypto Hash commands such as md5sum, sha256sum …
- [X] - Improve project’s web site design.
Build a standalone jarget by running
$ make sh
# Build
$ make sh
scala jarget.jar uber -scala -sh -o bin/jarget -m jarget.jar -j /home/archbox/opt/scala/lib/scala-xml_2.12-1.0.6.jar
Built file: bin/jarget ok
Run it with: $ java -jar bin/jarget
# Run it with
$ ./bin/jarget
# Or run it with
$ java -jar bin/jarget
# Or run it with
$ sh ./bin/jarget doc
Build a standalone jarget redeucing the app size with proguard.
- $ make pgd-unix
# Build
$ make pgd-unix -k CC=scalac
Makefile:63: warning: overriding recipe for target 'bin/jarget'
Makefile:58: warning: ignoring old recipe for target 'bin/jarget'
scalac src/logger.scala src/main.scala src/mvn.scala src/utils.scala src/reader.scala src/utils.JarBuilder.scala src/optPa
rser.scala src/crypto.scala -d jarget.jar
warning: there were 6 deprecation warnings (since 2.12.0); re-run with -deprecation for details
warning: there were 5 feature warnings; re-run with -feature for details
two warnings found
mkdir -p bin
cp -v exeLoaders/loaderCLI.exe exeLoaders/loaderGUI.exe assets || true
'exeLoaders/loaderCLI.exe' -> 'assets/loaderCLI.exe'
'exeLoaders/loaderGUI.exe' -> 'assets/loaderGUI.exe'
scala jarget.jar uber -scala -r=assets -o=bin/jarget-uber.jar jarget.jar /home/archbox/opt/scala/lib/scala-xml_2.12-1.0.6.
jar
java -jar proguard.jar @config.pro
ProGuard, version 5.3.3
Reading input...
Reading program jar [/home/archbox/Documents/projects/jarget.scala/bin/jarget-uber.jar]
Reading library jar [/home/archbox/opt/java/jre/lib/rt.jar]
Initializing...
... .... ...
Final number of program classes: 1123
Inlining subroutines...
Preverifying...
Writing output...
Preparing output jar [/home/archbox/Documents/projects/jarget.scala/bin/jarget-pro.jar]
Copying resources from program jar [/home/archbox/Documents/projects/jarget.scala/bin/jarget-uber.jar]
rm -rf bin/jarget-uber.jar
scala jarget.jar jar-to-exe -exe=uexe bin/jarget-pro.jar bin/jarget
Built file ./bin/jarget-pro
- make pgd-unix -k CC=scalac && make install
An fat-jar executable binary release can be downloaded from this link:
- Most update Snapshot jarget Download
- Release jarget v1.0
- Release jarget v1.1
- Release jarget v1.2
- Release jarget v1.3
- Release jarget v1.3.1
- Release jarget v1.3.2
- Release jarget v1.4.0 (5.7 MB)
From version >= 1.5 jarget will be shrunk with proguard.
- Release jarget v1.5.0 (1.7 MB)
- Release jarget v1.5.1
- Release jarget v2.0-beta - Added pacakge caching feature.
- Release jarget v2.0.1-beta - Allows scripting with dependencies (maven coordinates).
- Release jarget v2.1.0-beta - Uber-jars can be built with maven coordinates specifications and added more examples to documentation.
- Release jarget-v2.2.0-beta - Fixed uber-jars shell script header edge-case bug and also added command jarget utils -info to show platform informations such as number of processors, version of operating system, default line separator ‘\r’, ‘\n’, ‘\r\n’, path separator and so on.
- Release jarget-v3.0
- Improved command line handling allowing future scalability and implementation of new functionalities.
- Improved user interface. Now jarget has git-like subcommands. Each command works as it was a separated command line application in similar fashion to git and busybox.
- Implemented generation of uber jars embedded in Windows’ native executables. - (Still experimental.)
- Release jarget-v3.2
- Enhance commnand line help readability.
- Add commands jarget run
- Added more command examples in the sub-commands help.
- Add command jarget mvn-run-jar - to run standalone jar file from cache downloading it if not available yet. It allows to run proguard, rhino javascript engine, clojure and so on.
- Add command jarget mvn-run-cls - to run main class of java package. It is similar to mvn-run-jar, but mvn-run-cls is useful to run jars with multiple entry points (main classes).
- Release: jarget-v4.0
- Improve command line handling.
- Create build automation feature - to build project from configuration file.
Or it can be downloaded with those shell commands below:
$ curl -O -L https://github.com/caiorss/jarget/raw/gh-pages/jarget
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 130 100 130 0 0 28 0 0:00:04 0:00:04 --:--:-- 32
100 5675k 100 5675k 0 0 490k 0 0:00:11 0:00:11 --:--:-- 1011k
$ chmod +x jarget
$ ./jarget
jarget - Tool to download jar packages.
-show [package] - Show package's information
-pom [package] - Show package's pom file
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
Or
$ curl -O -L https://github.com/caiorss/jarget/raw/gh-pages/jarget && chmod +x jarget && ./jarget
On Windows the application can be executed with:
$ java -jar jarget
Jarget 3.2 - command line toolbox for Scala and the Java Platform.
Usage: $ [COMMAND] [OPTIONS] [<ARGS> ...]
Commands:
[Main Commands]
uber Build uber jar file for deployment by bundling dependencies and resource files.
exec Execute a shell command and pass -cp <CLASSPATH> of packages downloaded to it.
script Run a scala script with a given set of packages from cache.
scala Run Scala REPL (scala) passing the class of packages from the repository.
run Run a main class from a set of jar file passing the classpath of packages in repository.
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
On the Windows Operating Systems, the app can also be installed by running the commands below in the cmd.exe shell:
- Step 1 - Add ~/bin directory in $PATH variable.
# Create directory ~/bin or C:\Users\<user>\bin
C:\Users\archbox> mkdir %USERPROFILE%\bin
# Add bin directory in $PATH variable
setx PATH=%PATH%;%USERPROFILE%\bin
- Step 2 - Copy jarget to
C:\Users\<user>\bin
- Step 3 - Create a batch script to load the app at this directory, named jarget.bat with the contents below.
File: jarget.bat
@echo off
java -jar %~dp0\jarget %*
exit /b
- Step 4 - Open another cmd.exe shell to test. After typing $ jarget, it will show the user help below:
Microsoft Windows [Version 10.0.16299.371]
(c) 2017 Microsoft Corporation. All rights reserved.
C:\Users\archbox> jarget
Jarget 3.2 - command line toolbox for Scala and the Java Platform.
Usage: $ [COMMAND] [OPTIONS] [<ARGS> ...]
Commands:
C:\Users\archbox>
C:\Users\archbox>jarget.bat
Jarget 3.2 - command line toolbox for Scala and the Java Platform.
Usage: $ [COMMAND] [OPTIONS] [<ARGS> ...]
Commands:
C:\Users\archbox> where jarget
C:\Users\archbox\bin\jarget.bat
Now the app adopts git subcommands:
$ jarget
$ jarget
jarget v4.0 - command line toolbox for Scala and the Java Platform.
Usage: $ jarget [COMMAND] [OPTIONS] [<ARGS> ...]
Commands:
[Main Commands]
uber Build uber jar file for deployment by bundling dependencies and resource files.
exec Execute a shell command and pass -cp <CLASSPATH> of packages downloaded to it.
script Run a scala script with a given set of packages from cache.
scala Run Scala REPL (scala) passing the class of packages from the repository.
run Run a main class from a set of jar file passing the classpath of packages in repository.
[Mvn Commands]
mvn-show Show package's information.
mvn-search Search for a package at the site https://mvnrepository.com
mvn-doc Open package documentation in the web browser.
mvn-run-jar Run main method of executable jar package in repository.
mvn-run-cls Run a main class of a java package (class with main static method).
mvn-pom Show package's pom.xml file.
mvn-pull Download package to cache directory.
mvn-copy Copy jar packages from cache directory to ./lib downloading them if not available.
cache Show packages in cache directory.
[Jar Commands]
jar-to-exe Embed Uber jar into Unix executable or Windows Executable (experimental).
jar-man Show manifest of a jar file.
jar-main-class Show main class of a jar file.
jar-ls Show contents of a jar file.
jar-rs Show resources of a jar file ignoring *.class files.
jar-cat Show content of a file in a jar package.
jar-ex Extract <file> from jar file <FILE.jar> to current directory.
[Project Commands]
pj-show Show project configuration
pj-make Create development build.
pj-run Run development build, compiling it if out of sync with sources.
pj-release Compile project building uber jar in executable wrapper.
[Misc Commands]
utils General utilities helpers for platform information and debugging.
digest-s Compute crypto hash of string. - Algorithm: [md5 | sha1 | sha256 ]
digest-f Compute crypto hash of a file. - Algorithm: [md5 | sha1 | sha256 ]
Each sub-command has its own help:
- Example: subcommand uber to build uber jars.
$ jarget uber
Build uber jar file for deployment by bundling dependencies and resource files.
Note - <EXE> can be:
+ empty - (default) for jar file without any executable wrapper.
+ uexe - for Unix executable - Shell script with embedded uber-jar payload.
+ wcli - for Windows CLI command line executable. *.exe file.
+ wgui - for Windows GUI with user interface. -> *.exe file.
Usage: uber [OPTIONS] <MAIN-JAR> [<JARFILE1.jar> <JARFILE2.jar> ...]
OPTIONS:
-output=<file>, -o Output file, default out.jar
-scala, -s Bundle Scala runtime library scala-runtime.jar
-package=<pack>, -p MVN Coordinates of a java package - <group>/<artifact>/<version>.
-file=<file>, -f Jar files to be added to the package.
-resource=<folder>, -r Resource directory
-jardir=<folder>, -jd Directory containing jar files to be bundled into the uber jar.
-exe=<EXE>, -e Executable wrapper - default (empty).
- Example: subcommand cache
$ jarget cache
Show packages in cache directory.
Usage: cache <ACTION>
OPTIONS:
-path, - Show cache's directory path.
-pack, - Show packages in cache directory
-jars, - Show all jar files in cache directory
-clean, - Clean cache directory freeing space.
- $ jarget mvn-show org.jfree/jfreechart/1.0.17
$ jarget mvn-show
Show package's information.
Usage: mvn-show <PACKAGE>
$ jarget mvn-show org.jfree/jfreechart/1.0.17
Package: JFreeChart
Packaging: jar
Coordinates[1]: group = org.jfree artifact = jfreechart version = 1.0.17
Coordinates[2]: org.jfree/jfreechart/1.0.17
Url: http://www.jfree.org/jfreechart/
Description:
JFreeChart is a class library, written in Java, for generating charts.
Utilising the Java2D APIs, it currently supports bar charts, pie charts,
line charts, XY-plots and time series plots.
Dependencies:
- org.jfree/jcommon/1.0.21
- xml-apis/xml-apis/1.3.04
- $ jarget mvn-pom org.jfree/jfreechart/1.0.17
$ jarget mvn-pom
Show package's pom.xml file.
Usage: mvn-pom <PACKAGE>
$ jarget mvn-pom org.jfree/jfreechart/1.0.17
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-
v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<name>JFreeChart</name>
<artifactId>jfreechart</artifactId>
<groupId>org.jfree</groupId>
<version>1.0.17</version>
<packaging>jar</packaging>
... ... ... .... .... ...
- $ jarget mvn-doc org.jfree/jfreechart/1.0.17
It will open the package’s documentation at https://mvnrepository.com.
$ jarget mvn-doc
Open package documentation in the web browser.
Usage: mvn-doc <PACKAGE>
$ jarget mvn-doc org.jfree/jfreechart/1.0.17
This command installs/downloads all packages to jarget cache directory: file:~/.jarget/cache
- jarget mvn -pull -p=pack1 -p=pack2 -p=pack3…
Example: Get teh packages org.jfree/jfreechart/1.0.17 and org.scalaz/scalaz-core_2.11/7.3.0-M15.
$ jarget mvn-pull
Download package to cache directory.
Note: Packages are in the the format <group>/<artifact>/<version>
Usage: mvn-pull <PACKAGE1> [<PACKAGE2> ...]
Example:
$ jarget mvn-pull org.scalaz/scalaz-core_2.11/7.3.0-M15 org.jfree/jfreechart/1.0.17
$ jarget mvn-pull org.scalaz/scalaz-core_2.11/7.3.0-M15 org.jfree/jfreechart/1.0.17
Downloading ---------------------
PackData(org.scalaz,scalaz-core_2.11,7.3.0-M15)
PackData(org.scala-lang,scala-library,2.11.11)
PackData(org.scala-lang.modules,scala-java8-compat_2.11,0.7.0)
... ... ... ... ... ... ... ... ... ...
File /home/archbox/.jarget/cache/org/jfree/jcommon/1.0.21/jcommon-1.0.21.jar downloaded. Ok.
File /home/archbox/.jarget/cache/org/jfree/jfreechart/1.0.17/jfreechart-1.0.17.jar downloaded. Ok.
Download Successful
Show packages in cache:
$ jarget cache -pack
org.scala-lang/scala-library
xml-apis/xml-apis
org.scala-lang.modules/scala-java8-compat_2.11
org.scalaz/scalaz-core_2.11
org.jfree/jcommon
org.jfree/jfreechart
This command copies a package from cache to ./lib directory. The packages are downloaded if not available in the cache directory yet.
$ jarget mvn-copy org.jfree/jfreechart/1.0.17 org.scalaz/scalaz-core_2.11/7.3.0-M15
Downloading ---------------------
Downloading file /home/archbox/.jarget/cache/org/scala-lang/scala-library/2.11.11/scala-library-2.11.11.pom.
File /home/archbox/.jarget/cache/org/scalaz/scalaz-core_2.11/7.3.0-M15/scalaz-core_2.11-7.3.0-M15.pom downloaded. Ok.
Downloading file /home/archbox/.jarget/cache/org/scalaz/scalaz-core_2.11/7.3.0-M15/scalaz-core_2.11-7.3.0-M15.jar.
File /home/archbox/.jarget/cache/org/scala-lang/scala-library/2.11.11/scala-library-2.11.11.pom downloaded. Ok.
Downloading file /home/archbox/.jarget/cache/org/scala-lang/scala-library/2.11.11/scala-library-2.11.11.jar.
File /home/archbox/.jarget/cache/org/scala-lang/modules/scala-java8-compat_2.11/0.7.0/scala-java8-compat_2.11-0.7.0.pom downloaded. Ok.
Downloading file /home/archbox/.jarget/cache/org/scala-lang/modules/scala-java8-compat_2.11/0.7.0/scala-java8-compat_2.11-0.7.0.jar.
File /home/archbox/.jarget/cache/org/scala-lang/modules/scala-java8-compat_2.11/0.7.0/scala-java8-compat_2.11-0.7.0.jar downloaded. Ok.
File /home/archbox/.jarget/cache/org/scala-lang/scala-library/2.11.11/scala-library-2.11.11.jar downloaded. Ok.
File /home/archbox/.jarget/cache/org/scalaz/scalaz-core_2.11/7.3.0-M15/scalaz-core_2.11-7.3.0-M15.jar downloaded. Ok.
Download Successful
Copying xml-apis-1.3.04.jar to ./lib
Copying scalaz-core_2.11-7.3.0-M15.jar to ./lib
Copying scala-library-2.11.11.jar to ./lib
Copying jfreechart-1.0.17.jar to ./lib
Copying jcommon-1.0.21.jar to ./lib
Copying scala-java8-compat_2.11-0.7.0.jar to ./lib
$ ls lib/
jcommon-1.0.21.jar scala-java8-compat_2.11-0.7.0.jar scalaz-core_2.11-7.3.0-M15.jar
jfreechart-1.0.17.jar scala-library-2.11.11.jar xml-apis-1.3.04.jar
$ rm -rf lib
When the command is run the second time, the packages are copied from cache to ./lib.
$ jarget mvn-copy org.jfree/jfreechart/1.0.17 org.scalaz/scalaz-core_2.11/7.3.0-M15
Copying xml-apis-1.3.04.jar to ./lib
Copying scalaz-core_2.11-7.3.0-M15.jar to ./lib
Copying scala-library-2.11.11.jar to ./lib
Copying jfreechart-1.0.17.jar to ./lib
Copying jcommon-1.0.21.jar to ./lib
Copying scala-java8-compat_2.11-0.7.0.jar to ./lib
- $ jarget mvn -clear
$ jarget mvn -clear
Cleaning cache
Removing file: /home/archbox/.jarget/cache/xml-apis/xml-apis/1.3.04/xml-apis-1.3.04.pom
Removing file: /home/archbox/.jarget/cache/xml-apis/xml-apis/1.3.04/xml-apis-1.3.04.jar
... ... ... ... ...
Deleting directory: /home/archbox/.jarget/cache/xml-apis/xml-apis/1.3.04
Deleting directory: /home/archbox/.jarget/cache/xml-apis/xml-apis
Deleting directory: /home/archbox/.jarget/cache/xml-apis
Deleting directory: /home/archbox/.jarget/cache
- $ jarget exec -p=pack1 -p=pack2 … – program arg1 arg2 arg2 …
It will execute a program with arguments arg1, arg2 and arg3 passing
the option -cp <classpath of pack1,pack2,..,packn>
, where (-cp)
argument is the class path of the packages pack1,pack2… from the
cache directory ~/.jarget/cache, to it. So the program will be
executed with:
- $ program -cp <classpath of pack1,pack2…> arg1 arg2 arg3 …
NOTE: The packages are downloaded to cache if not available yet.
Command help:
$ jarget exec
Execute a shell command and pass -cp <CLASSPATH> of packages downloaded to it.
Usage: exec [OPTIONS] -- <PROGRAM> [<PROGRAM ARGS> ...]
-package=<PACK> -p=<PACK> Package maven's coordinate
Example: Run Scala with org.typelevel/cats-core_2.12/0.9.0
$ jarget exec -p=org.typelevel/cats-core_2.12/0.9.0 -- scala
Downloading ---------------------
... ... ... ...
Package path = PackData(org.typelevel,cats-macros_2.12,0.9.0)
Downloading file /home/archbox/.jarget/cache/org/typelevel/cats-macros_2.12/0.9.0/cats-macros_2.12-0.9.0.pom.
... .... ... .... ...
File /home/archbox/.jarget/cache/org/scala-lang/scala-library/2.12.1/scala-library-2.12.1.jar downloaded. Ok.
Download Successful
Welcome to Scala 2.12.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_162).
Type in expressions for evaluation. Or try :help.
scala>
scala> import cats._, cats.instances.all._
import cats._
import cats.instances.all._
scala> val len: String => Int = _.length
len: String => Int = $$Lambda$1041/28318221@2ed71727
scala>
scala> Functor[List].map(List("scala", "cats")) (len)
res0: List[Int] = List(5, 4)
scala>
Run script with scala and dependencies
It runs the script scripts/chartTest.scala with jfreechart library in passed to scala classpath.
$ jarget exec -p=org.jfree/jfreechart/1.0.17 -- scala scripts/chartTest.scala
The command above runs:
scala -cp <classpath of org.jfree/jfreechart/1.0.17> scripts/chartTest.scala
Compile scala program with dependencies
$ jarget exec -p=org.jfree/jfreechart/1.0.17 -- scalac scripts/chartTest.scala -d chart.jar
$ file chart.jar
chart.jar: Java archive data (JAR)
# Run the program:
$ jarget exec -p=org.jfree/jfreechart/1.0.17 -- scala chart.jar
This sub command runs an executable jar (uber jar) from cache repository, the package is downloaded if not available yet.
Command help:
$ jarget mvn-run-jar
Run main method of executable jar package in repository.
Usage: mvn-run-jar <PACKAGE> -- [<ARGS>...]
Example 1 : This command download the file proguard-base-6.0.2.jar
to the cache repository and runs the command java -jar <path-to-jar>/proguard-base-6.0.2.jar
Once the file was downloaded, it will be run from cache repository.
>> $ jarget mvn-run-jar net.sf.proguard/proguard-base/6.0.2
Example 2 :
>> $ jarget mvn-run-jar org.codehaus.groovy/groovy/2.5.0-rc-1 -- file1.groovy
Example 3: Show Clojure help, to run the repl remove (--help) switch.
>> $ jarget mvn-run-jar org.clojure/clojure/1.8.0 -- --help
Example: It downloads the clojure 1.8.0 package and runs the command
- $ java -jar <path-to-package>/clojure-1.8.0.jar
$ jarget mvn-run-jar org.clojure/clojure/1.8.0
Downloading ---------------------
PackData(org.clojure,clojure,1.8.0)
----------------------------------
Package path = PackData(org.clojure,clojure,1.8.0)
Downloading file /home/archbox/.jarget/cache/org/clojure/clojure/1.8.0/clojure-1.8.0.pom.
File /home/archbox/.jarget/cache/org/clojure/clojure/1.8.0/clojure-1.8.0.pom downloaded. Ok.
Downloading file /home/archbox/.jarget/cache/org/clojure/clojure/1.8.0/clojure-1.8.0.jar.
File /home/archbox/.jarget/cache/org/clojure/clojure/1.8.0/clojure-1.8.0.jar downloaded. Ok.
Download Successful
Clojure 1.8.0
user=>
user=> (+ 1 2 3 4 5 6)
21
user=> (* 1 2 3 4 5 6)
720
user=>
$ jarget mvn-run-cls
Run a main class of a java package (class with main static method).
Note: this command is useful to run packages with multiple entry points.
Usage: mvn-run-cls <PACKAGE> <CLASS> [<JAVA-PROPERTIES> ...] -- [<ARGS>...]
Example 1: Run scala compiler and invokes -help by calling class scala.tools.nsc.Main.
If the scala compiler packages are not in the cache, they will be downloaded. Further
commands needing those packages will no longer downloaded them.
>>> $ jarget mvn-run-cls org.scala-lang.virtualized/scala-compiler/2.11.2 \
scala.tools.nsc.Main -Dscala.usejavacp=true -- -help
Example 2: It will run the Scala REPL.
>>> $ jarget mvn-run-cls org.scala-lang.virtualized/scala-compiler/2.11.2 \
scala.tools.nsc.MainGenericRunner -Dscala.usejavacp=true
Example: This command downloads the package rg.scala-lang.virtualized/scala-compiler/2.11.2 and all its dependencies if not available at cache repository, then it runs the class scala.tools.nsc.MainGenericRunner which invokes the Scala’s REPL interactive shell.
This command is useful to run classes of packages with multiple entry-points (main classes).
$ jarget mvn-run-cls org.scala-lang.virtualized/scala-compiler/2.11.2 \
scala.tools.nsc.MainGenericRunner -Dscala.usejavacp=true
$ jarget mvn-run-cls org.scala-lang.virtualized/scala-compiler/2.11.2 \
> scala.tools.nsc.MainGenericRunner -Dscala.usejavacp=true
Downloading ---------------------
PackData(org.scala-lang.virtualized,scala-compiler,2.11.2)
PackData(org.scala-lang.modules,scala-xml_2.11,1.0.2)
PackData(org.scala-lang.virtualized,scala-library,2.11.2)
PackData(org.scala-lang.virtualized,scala-reflect,2.11.2)
PackData(jline,jline,2.12)
PackData(org.scala-lang.modules,scala-parser-combinators_2.11,1.0.1)
----------------------------------
Package path = PackData(org.scala-lang.virtualized,scala-compiler,2.11.2)
Downloading file /home/archbox/.jarget/cache/org/scala-lang/virtualized/scala-compiler/2.11.2/scala-compiler-2.11.2.pom.
Package path = PackData(org.scala-lang.modules,scala-xml_2.11,1.0.2)
Package path = PackData(org.scala-lang.virtualized,scala-library,2.11.2)
... .... ... ...
Download Successful
Welcome to Scala version 2.11.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_162).
Type in expressions to have them evaluated.
Type :help for more information.
scala>
scala> import javax.swing._
import javax.swing._
scala> val frame = new JFrame("Hello world")
frame: javax.swing.JFrame = javax.swing.JFrame[frame0,0,27,0x0,invalid,.... ....
scala> frame.setSize(400, 500)
scala> frame.setVisible(true)
$ jarget run
Run a main class from a set of jar file passing the classpath of packages in repository.
Usage: run [OPTIONS] <MAIN-CLASS> <JAR0> [<JAR1> ....] [<JAVA-PROPERTIES> ...] -- [<ARGS>...]
OPTIONS:
-package=<pack>, -p MVN Coordinates of a java package - <group>/<artifact>/<version>.
+ <MAIN-CLASS> : Is the a class with a main static method that will be executed.
+ <JAR0> : Is a jar package such as ImageViewer.jar
+ <ARGS> : Are the arguments passed to the main class.
Example and use case: Run the class Main from the jar
demoImageViewer.jar passing the classpath of the package
com.jtattoo/JTattoo/1.6.11 from (http://www.jtattoo.net/) and setting
the property swing.defaultlaf that changes to Java Swing default look
and feel theme.
$ jarget run Main demoImageViewer.jar -p=com.jtattoo/JTattoo/1.6.11 \
-Dswing.defaultlaf=com.jtattoo.plaf.hifi.HiFiLookAndFeel
- $ jarget cache -path
Example:
$ jarget cache -path
/home/archbox/.jarget/cache
$ tree $(jarget cache -path)
/home/archbox/.jarget/cache
├── com
│ └── github
│ └── mpilquist
│ └── simulacrum_2.12
│ └── 0.10.0
│ ├── simulacrum_2.12-0.10.0.jar
│ └── simulacrum_2.12-0.10.0.pom
└── org
├── scala-lang
│ └── scala-library
│ └── 2.12.1
│ ├── scala-library-2.12.1.jar
│ └── scala-library-2.12.1.pom
└── typelevel
├── cats-core_2.12
│ └── 0.9.0
│ ├── cats-core_2.12-0.9.0.jar
│ └── cats-core_2.12-0.9.0.pom
├── cats-kernel_2.12
│ └── 0.9.0
│ ├── cats-kernel_2.12-0.9.0.jar
│ └── cats-kernel_2.12-0.9.0.pom
├── cats-macros_2.12
│ └── 0.9.0
│ ├── cats-macros_2.12-0.9.0.jar
│ └── cats-macros_2.12-0.9.0.pom
└── machinist_2.12
└── 0.6.1
├── machinist_2.12-0.6.1.jar
└── machinist_2.12-0.6.1.pom
- $ jarget cache -pack
$ jarget cache -pack
org.scala-lang/scala-library
org.typelevel/cats-core_2.12
org.typelevel/cats-macros_2.12
org.typelevel/cats-kernel_2.12
org.typelevel/machinist_2.12
com.github.mpilquist/simulacrum_2.12
$ jarget cache -jars
/home/archbox/.jarget/cache/org/typelevel/cats-macros_2.12/0.9.0/cats-macros_2.12-0.9.0.jar
/home/archbox/.jarget/cache/org/typelevel/machinist_2.12/0.6.1/machinist_2.12-0.6.1.jar
/home/archbox/.jarget/cache/org/typelevel/cats-core_2.12/0.9.0/cats-core_2.12-0.9.0.jar
/home/archbox/.jarget/cache/org/typelevel/cats-kernel_2.12/0.9.0/cats-kernel_2.12-0.9.0.jar
/home/archbox/.jarget/cache/org/scala-lang/scala-library/2.12.1/scala-library-2.12.1.jar
/home/archbox/.jarget/cache/com/github/mpilquist/simulacrum_2.12/0.10.0/simulacrum_2.12-0.10.0.jar
Jarget can be used to run scala scripts with java packages dependencies by downloading them if they are not available in the jarget package cache file:~/.jarget/cache.
Show command help:
$ jarget script
Run a scala script with a given set of packages from cache.
Usage: script [OPTIONS] -- <SCRIPT.scala> [<SCRIPT ARGS> ...]
OPTIONS:
-package=<PACK>, -p Package maven's coordinate
-package-str=<PACK1>,<PACK2>..., -ps Package's separated by command <pack1>,<pack2>...<packN>
Example: scripts/chartScript.sh
#!/bin/sh
DEPS=org.jfree/jfreechart/1.0.17
exec jarget script -ps="$DEPS" -- "$0" "$@"
!#
import org.jfree.chart.{ChartPanel, ChartFactory, JFreeChart, ChartUtilities}
import org.jfree.data.general.DefaultPieDataset
object Main{
def main(args: Array[String]){
val dataset = new DefaultPieDataset()
dataset.setValue("A", 75)
dataset.setValue("B", 10)
dataset.setValue("C", 10)
dataset.setValue("D", 5)
val chart = ChartFactory.createPieChart(
"Sample Pie Chart", // Title
dataset, // Dataset
true, // Show legend
true, // Tooltips on
false
)
// Save chart to a png file
//---------------------------
ChartUtilities.saveChartAsPNG(new java.io.File("mychart.png"), chart, 500, 500)
// Show Chart in a Java Swing Frame
//--------------------------------------
val frame = new javax.swing.JFrame()
frame.add(new ChartPanel(chart))
frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE)
frame.setSize(693, 513)
frame.setTitle("Sample Pie Chart")
frame.setVisible(true)
}
}
Running the scala script: It is assumed that jarget is in any directory listed in ‘$PATH’ variable.
# Make the script executable
$ chmod +x chartScript.sh
# As the dependency jfree chart package has not been downloaded yet,
# jarget will download it to the cache directory and run the scala script 'chartScript.scala'
# passing the dependency in the classpath parameter.
#
$ ./chartScript.sh
Downloading ---------------------
PackData(org.jfree,jfreechart,1.0.17)
PackData(org.jfree,jcommon,1.0.21)
PackData(xml-apis,xml-apis,1.3.04)
----------------------------------
Package path = PackData(org.jfree,jfreechart,1.0.17)
Downloading file /home/archbox/.jarget/cache/org/jfree/jfreechart/1.0.17/jfreechart-1.0.17.pom.
Package path = PackData(org.jfree,jcommon,1.0.21)
Package path = PackData(xml-apis,xml-apis,1.3.04)
... ... ... ... ...
File /home/archbox/.jarget/cache/org/jfree/jcommon/1.0.21/jcommon-1.0.21.jar downloaded. Ok.
File /home/archbox/.jarget/cache/org/jfree/jfreechart/1.0.17/jfreechart-1.0.17.jar downloaded. Ok.
Download Successful
# When the scala script is run again and the dependencies are in the
# cache directory ~/.jarget/cache, the dependencies no longer needs to
# be downloaded and the script is executed immediately by passing the
# dependencies' classpath to scala runtime.
#
$ ./chartScript.sh
This script generates a QRCode from argument passed from command line saving it to an image file or showing it with a JFrame window.
File: scripts/qrcode.sh
#!/bin/sh
DEPS=com.google.zxing/core/2.2,com.google.zxing/javase/2.2
exec jarget script -ps="$DEPS" -- "$0" "$@"
!#
object QRCode {
import javax.imageio.ImageIO;
import java.io._
import java.util.HashMap
import com.google.zxing.{BarcodeFormat, BinaryBitmap, EncodeHintType, MultiFormatReader}
import com.google.zxing.{MultiFormatWriter, NotFoundException, Result, WriterException}
import com.google.zxing.client.j2se.MatrixToImageWriter
import com.google.zxing.common.{ BitMatrix, HybridBinarizer}
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel
def writeToFile(
data: String,
file: String = "out.png",
width: Int = 200,
height: Int = 200,
charset: String = "UTF-8") = {
val hintMap = {
val h = new HashMap[EncodeHintType, ErrorCorrectionLevel]();
h.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
h
}
val matrix = new MultiFormatWriter().encode(
new String(data.getBytes(charset), charset),
BarcodeFormat.QR_CODE, width, height, hintMap)
MatrixToImageWriter.writeToFile(matrix, "png", new File(file));
}
def writeToImage(
data: String,
width: Int = 200,
height: Int = 200,
charset: String = "UTF-8" ): java.awt.image.BufferedImage = {
val hintMap = {
val h = new HashMap[EncodeHintType, ErrorCorrectionLevel]();
h.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
h
}
val matrix = new MultiFormatWriter().encode(
new String(data.getBytes(charset), charset),
BarcodeFormat.QR_CODE, width, height, hintMap)
MatrixToImageWriter.toBufferedImage(matrix)
}
/** Show QR code in a JFrame */
def show(
data: String,
width: Int = 200,
height: Int = 200,
charset: String = "UTF-8",
title: String = "QRCode",
exitOnClose: Boolean = false
) = {
import javax.swing.{ImageIcon, JFrame, JLabel, JPanel}
val bimg = writeToImage(data, width, height, charset)
val frame = new javax.swing.JFrame("Frame 1")
frame.setSize(400, 400)
val pic = new javax.swing.JLabel(new ImageIcon(bimg))
frame.add(pic)
if (exitOnClose)
frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE)
frame.setVisible(true)
}
} // ------- End of Object QRCode ------------ //
val testUrl = "https://msdn.microsoft.com/en-us/library/ff798384.aspx"
args.toList match {
case List("-show", data)
=> QRCode.show(data, exitOnClose = true)
case List("-file", data, file)
=> QRCode.writeToFile(data, file)
case List("-test1")
=> {
println("Generating QRcode for testing URL: " + testUrl)
QRCode.show(testUrl, exitOnClose = true)
}
case List("-test2")
=> {
println("Generating QRcode image file images/qrcodeTest.png for testing URL: " + testUrl)
QRCode.writeToFile(testUrl, "images/qrcodeTest.png")
}
case _
=> {
println("Valid commands")
println("$ jqrcode -file <file> <data>")
println("$ jqrcode -show <data>")
}
}
Running
$ scripts/qrcode.sh
Valid commands
$ jqrcode -file <file> <data>
$ jqrcode -show <data>
Generating image with QRcode.
It will generate a QRCode shown in the image below containing “Hello world QRCode”. The script dependencies are downloaded to the cache directory if they are not available yet.
$ scripts/qrcode.sh -file "Hello world QRCode" images/qrcode.png
Downloading ---------------------
PackData(com.google.zxing,core,2.2)
----------------------------------
Package path = PackData(com.google.zxing,core,2.2)
Downloading file /home/archbox/.jarget/cache/com/google/zxing/core/2.2/core-2.2.pom.
File /home/archbox/.jarget/cache/com/google/zxing/core/2.2/core-2.2.pom downloaded. Ok.
Downloading file /home/archbox/.jarget/cache/com/google/zxing/core/2.2/core-2.2.jar.
File /home/archbox/.jarget/cache/com/google/zxing/core/2.2/core-2.2.jar downloaded. Ok.
Download Successful
Downloading ---------------------
PackData(com.google.zxing,javase,2.2)
----------------------------------
Package path = PackData(com.google.zxing,javase,2.2)
Downloading file /home/archbox/.jarget/cache/com/google/zxing/javase/2.2/javase-2.2.pom.
File /home/archbox/.jarget/cache/com/google/zxing/javase/2.2/javase-2.2.pom downloaded. Ok.
Downloading file /home/archbox/.jarget/cache/com/google/zxing/javase/2.2/javase-2.2.jar.
File /home/archbox/.jarget/cache/com/google/zxing/javase/2.2/javase-2.2.jar downloaded. Ok.
Download Successful
File: images/qrcode.png
Show QRcode in a window
$ scripts/qrcode.sh -show "Hello world QRCode"
$ scripts/qrcode.sh -test1
Generating QRcode for testing URL: https://msdn.microsoft.com/en-us/library/ff798384.aspx
$ scripts/qrcode.sh -test2
Generating QRcode image file images/qrcodeTest.png for testing URL: https://msdn.microsoft.com/en-us/library/ff798384.aspx
The commands to manipulate jars are listed below:
$ jarget | grep jar
uber Build uber jar file for deployment by bundling dependencies and resource files.
run Run a main class from a set of jar file passing the classpath of packages in repository.
mvn-run-jar Run main method of executable jar package in repository.
mvn-copy Copy jar packages from cache directory to ./lib downloading them if not available.
jar-to-exe Embed Uber jar into Unix executable or Windows Executable (experimental).
jar-man Show manifest of a jar file.
jar-main-class Show main class of a jar file.
jar-ls Show contents of a jar file.
jar-rs Show resources of a jar file ignoring *.class files.
jar-cat Show content of a file in a jar package.
jar-ex Extract <file> from jar file <FILE.jar> to current directory.
Those commands are simple and self-explanatory and easier to remember.
$ jarget jar-ls -h
Show contents of a jar file.
Usage: jar-ls <FILE.jar>
$ jarget jar-ex -h
Extract <file> from jar file <FILE.jar> to current directory.
Usage: jar-ex <FILE.jar> <file>
$ jarget jar-to-exe
Embed Uber jar into Unix executable or Windows Executable (experimental).
Usage: jar-to-exe [OPTIONS] <FILE.jar>
OPTIONS:
-exe=<EXE>, -e Executable type.
-output=<FILE>, -o Output file, default <FILE> without extension + .sh or .exe.
Note - <EXE> can be:
+ uexe - for Unix executable - Shell script with embedded uber-jar payload.
+ wcli - for Windows CLI command line executable. *.exe file.
+ wgui - for Windows GUI with user interface. -> *.exe file.
- $ jarget jar-man JARFILE.jar
$ jarget jar-man lib/jfreechart-1.0.17.jar
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Implementation-Title: JFreeChart
Implementation-Version: 1.0.17
Specification-Vendor: jfree.org
Specification-Title: JFreeChart
Created-By: 1.7.0_21-b12 (Oracle Corporation)
Specification-Version: 1.0.17
Implementation-Vendor: jfree.org
- $ jarget jar-cat [jar] [file]
$ jarget jar-cat lib/jfreechart-1.0.17.jar META-INF/MANIFEST.MF
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.7.0_21-b12 (Oracle Corporation)
Specification-Title: JFreeChart
Specification-Version: 1.0.17
Specification-Vendor: jfree.org
Implementation-Title: JFreeChart
Implementation-Version: 1.0.17
Implementation-Vendor: jfree.org
... .... ... .... ... .... ... .... ... ....
$ jarget jar-cat lib/jfreechart-1.0.17.jar org/jfree/chart/plot/LocalizationBundle_pt_PT.properties
# org.jfree.chart.ChartPanel ResourceBundle properties file - portuguese version
#
# Changes (from 09-Set-2003)
# --------------------------
# 09-Set-2003 : Initial version (Eduardo Ramalho);
#
Category_Plot=Barras
Combined_Domain_XYPlot=Curvas combinadas pela abcissa
Combined_Range_XYPlot=Curvas combinadas pela ordenada
Compass_Plot=Compasso
Contour_Plot=Contours
Fast_Scatter_Plot=Dispers\u00E3o
Meter_Plot=N\u00EDvel
Period_Marker_Plot=Period Marker Plot
Pie_Plot=Sectores
Thermometer_Plot=Term\u00a2metro
XY_Plot=Curvas
Pie_3D_Plot=Sectores 3D
Too_many_elements=Too many elements
# points of the compass
N=N
E=E
S=S
W=W
- $ jarget jar-ls [jar]
$ jarget jar-ls jarget.jar
META-INF/MANIFEST.MF
PackData.class
PackData$.class
PomData.class
PomData$.class
Utils.class
Utils$.class
JarUtils.class
JarUtils$.class
Packget.class
Packget$.class
Main.class
Main$.class
Packget$$anonfun$downloadPackage$4.class
Packget$$anonfun$downloadPackage$5.class
- $ jarget jar-rs [jar]
Show all resource files disregarding *.class files.
$ jarget jar-rs lib/jfreechart-1.0.17.jar
META-INF/MANIFEST.MF
org/jfree/chart/LocalizationBundle.properties
org/jfree/chart/LocalizationBundle_cs.properties
org/jfree/chart/LocalizationBundle_de.properties
org/jfree/chart/LocalizationBundle_es.properties
org/jfree/chart/LocalizationBundle_fr.properties
org/jfree/chart/LocalizationBundle_it.properties
... ... ... ... ... ... ... ... ... ... ... ...
org/jfree/chart/plot/LocalizationBundle_ru.properties
org/jfree/chart/plot/LocalizationBundle_zh_CN.properties
- jarget jar -extract [jar] [file]
Extract file from jar to current directory.
$ jarget jar-ex -h
Extract <file> from jar file <FILE.jar> to current directory.
Usage: jar-ex <FILE.jar> <file>
$ jarget jar-ex lib/jfreechart-1.0.17.jar META-INF/MANIFEST.MF
$ cat MANIFEST.MF
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.7.0_21-b12 (Oracle Corporation)
Specification-Title: JFreeChart
Specification-Version: 1.0.17
Specification-Vendor: jfree.org
Implementation-Title: JFreeChart
Implementation-Version: 1.0.17
Implementation-Vendor: jfree.org
Show Help:
$ jarget jar-to-exe
Embed Uber jar into Unix executable or Windows Executable (experimental).
Usage: jar-to-exe [OPTIONS] <FILE.jar>
OPTIONS:
-exe=<EXE>, -e Executable type.
-output=<FILE>, -o Output file, default <FILE> without extension + .sh or .exe.
Note - <EXE> can be:
+ uexe - for Unix executable - Shell script with embedded uber-jar payload.
+ wcli - for Windows CLI command line executable. *.exe file.
+ wgui - for Windows GUI with user interface. -> *.exe file.
Examples:
- $ jarget jar-to-exe application.jar
Generates an Unix shell script with a jar payload, named ./application
from the file application.jar that can be run with $ java -jar application.jar
Example: Generate a *nix executable (runnable or self-executable jar file) named proguard from proguard.jar.
$ java -jar proguard.jar
ProGuard, version 5.3.3
Usage: java proguard.ProGuard [options ...]
# Builds Unix executable with embedded shell script
$ jarget jar-to-exe proguard.jar
Built file ./proguard
# Build Windows executable with proguard embedded - (Note: Experimental)
$ jarget jar-to-exe -exe=wcli proguard.jar
Built file ./proguard.exe
$ proguard
bash: proguard: command not found
# If the app is moved to some directory in $PATH variable,
# it can be ran without forward slash (/) as any ordinary unix app
# such as ls, echo, ps, ...
$ mv proguard ~/bin
$ proguard
ProGuard, version 5.3.3
Usage: java proguard.ProGuard [options ...]
$ which proguard
/home/archbox/bin/proguard
# Check the file type
##
$ file /home/archbox/bin/proguard
/home/archbox/bin/proguard: a /usr/bin/env sh script executable (binary data)
# Check the executable header
##
$ head -n 7 proguard
#!/usr/bin/env sh
# Check if JAVA_HOME is Set
if [ -n "${JAVA_HOME}" ]
then
# Check if JAVA is Installed in this JAVA_HOME
if [ -f "$JAVA_HOME/bin/java" ] ;
Help:
$ jarget uber
Build uber jar file for deployment by bundling dependencies and resource files.
Note - <EXE> can be:
+ empty - (default) for jar file without any executable wrapper.
+ uexe - for Unix executable - Shell script with embedded uber-jar payload.
+ wcli - for Windows CLI command line executable. *.exe file.
+ wgui - for Windows GUI with user interface. -> *.exe file.
Usage: uber [OPTIONS] <MAIN-JAR> [<JARFILE1.jar> <JARFILE2.jar> ...]
OPTIONS:
-output=<file>, -o Output file, default out.jar
-scala, -s Bundle Scala runtime library scala-runtime.jar
-package=<pack>, -p MVN Coordinates of a java package - <group>/<artifact>/<version>.
-file=<file>, -f Jar files to be added to the package.
-resource=<folder>, -r Resource directory
-jardir=<folder>, -jd Directory containing jar files to be bundled into the uber jar.
-exe=<EXE>, -e Executable wrapper - default (empty).
The parameter <EXE> from -exe=<EXE> can be:
- empty -> (default) Simple uber jar intended to be executed by double clicking at it or by
- uexe -> Unix executable: Shell script with uber jar payload
- wcli -> Embed generated uber-jar into a Windows command line executable. This feature is still experimental and Anti Virus complains about the lack of signature.
- wgui -> Embed generated uber-jar into a Windows GUI executable. This feature is still experimental.
Example: Make a scala uber-jar from the program scripts/chartTest.scala
# Step 1 - Compile app to jar file.
#
# If the dependency is not available in the cache, it will be downloaded
# from the package default repository.
#
$ jarget exec -p=org.jfree/jfreechart/1.0.17 -- scalac scripts/chartTest.scala -d chartTest.jar
Downloading ---------------------
PackData(org.jfree,jfreechart,1.0.17)
PackData(org.jfree,jcommon,1.0.21)
PackData(xml-apis,xml-apis,1.3.04)
----------------------------------
... ... ... ... ... ... ... ... ...
Downloading file /home/archbox/.jarget/cache/xml-apis/xml-apis/1.3.04/xml-apis-1.3.04.jar.
File /home/archbox/.jarget/cache/xml-apis/xml-apis/1.3.04/xml-apis-1.3.04.jar downloaded. Ok.
File /home/archbox/.jarget/cache/org/jfree/jcommon/1.0.21/jcommon-1.0.21.jar downloaded. Ok.
File /home/archbox/.jarget/cache/org/jfree/jfreechart/1.0.17/jfreechart-1.0.17.jar downloaded. Ok.
Download Successful
# The next time the command is run, the packages will no longer be downloaded as
# they are already in the cache directory. ~/.jarget/cache/
#
$ jarget exec -p=org.jfree/jfreechart/1.0.17 -- scalac scripts/chartTest.scala -d chartTest.jar
# Step 2 - Run the jar file.
#
$ jarget exec -p=org.jfree/jfreechart/1.0.17 -- scala chartTest.jar
# Step 3 - Make uber-jar by packing dependencies into a single jar.
#-- Create an ordinary uber jar that can be run with java -jar or by clicking on it,
# if the application is a GUI.
$ jarget uber chartTest.jar -scala -p=org.jfree/jfreechart/1.0.17
Built file: chartTest-out.jar
# -- Embedding in a shell script for running on UNIX, Linux, MacOSX, BSD ...
$ jarget uber chartTest.jar -o=chartTest.sh -scala -exe=uexe -p=org.jfree/jfreechart/1.0.17
#--- Embedding Uber jar into an Windows Executable
$ jarget uber chartTest.jar -o=chartTest.exe -scala -exe=wgui -p=org.jfree/jfreechart/1.0.17
$ file chartTest.exe
chartTest.exe: PE32 executable (GUI) Intel 80386, for MS Windows
# Run the uber-jar - Way 1
$ ./chartTest.sh
# Run the uber-jar - Way 2
$ java -jar ./chartTest.sh
# Run the uber-jar - Way 3
$ sh ./chartTest.sh
Example: Make a scala self-executable jar for the app jarget.
$ scala jarget.jar uber -scala -sh -o jarget -m jarget.jar -j /home/archbox/opt/scala-2.12.3/lib/scala-xml_2.12-1.0.6.jar
Built file: jarget ok
Run it with: $ java -jar jarget
# Run it
$ ./jarget
WARNING: Experimental feature.
Jarget has the ability build small or simple projects with a simple configuration file with a declarative json-like syntax provided by the parser library https://github.com/lightbend/config.
Example:
- File: build.conf
scalaVersion = 2.12
# Name of the library, program or application without extension.
app = jptk
# Directories containing source that will be compiled
src = ./proejct/src
# Output file - destination of object files
output = ./out
# Depdencies in the format (com.typesafe/config/1.3.3)
packages = [
org.typelevel/cats-core_2.12/0.9.0,
org.beanshell/bsh/2.0b5,
org.codehaus.groovy/groovy-all/2.4.15
]
# List of resource directories that will be appended to release build
resources = [
./assets
]
Explanation:
- app = <name of application>
- src = <directory which contains source code> *.scala files.
- Default value: ./src
- output = <output directory>
- Default value: ./bin
- packages
Project Commands:
- Show project file:
$ cat build.conf
# Jarget configuration file
scalaVersion = 2.12
# Program name without any extension
app = jmhttp
# Main class
mainclass = JargetMain
# Directories that will be compiled (default ./src)
src = src
# Output Directory (default ./bin)
output = ./bin
# Depdencies
packages = [
javax.jmdns/jmdns/3.4.1
]
# resources = [
# ./assets
# ]
- Show build details.
$ jarget pj-show -h
Show project configuration
USAGE: $ jarget pj-show
OPTIONS:
-file=<FILE>, -f Project file. (default build.conf)
$ jarget pj-show
Source directory = src
Development build output file = ./bin/jmhttp-dev.jar
Output directory = ./bin
Scala Version = 2.12
Source files:
------------------------------------
- src/server.scala
- src/utils.Utils.scala
- src/utils.ImageUtils.scala
- src/main.scala
- src/optParse.scala
Dependencies:
------------------------------------
- javax.jmdns/jmdns/3.4.1
- Carry out development build (build without any bundled dependency and cannot be run as standalone app.)
$ jarget pj-make -h
Create development build.
Note: the development build is the project compiled without
any dependency bundled with object file.
USAGE: $ jarget pj-make
OPTIONS:
-file=<FILE>, -f Project file. (default build.conf)
-verbose, - Turn verbosity on.
$ jarget pj-make
Downloading ---------------------
PackData(javax.jmdns,jmdns,3.4.1)
----------------------------------
Package path = PackData(javax.jmdns,jmdns,3.4.1)
Downloading file /home/archbox/.jarget/cache/javax/jmdns/jmdns/3.4.1/jmdns-3.4.1.pom.
File /home/archbox/.jarget/cache/javax/jmdns/jmdns/3.4.1/jmdns-3.4.1.pom downloaded. Ok.
Downloading file /home/archbox/.jarget/cache/javax/jmdns/jmdns/3.4.1/jmdns-3.4.1.jar.
File /home/archbox/.jarget/cache/javax/jmdns/jmdns/3.4.1/jmdns-3.4.1.jar downloaded. Ok.
Download Successful
# Generates:
$ ls bin/jmhttp-dev.jar
bin/jmhttp-dev.jar
- Run the develpment build.
$ jarget pj-run -h
Run development build, compiling it if out of sync with sources.
-
USAGE: $ jarget pj-run pj-run -- [<PROGRAM ARG> ...]
OPTIONS:
-file=<FILE>, -f Project file. (default build.conf)
$ jarget pj-run
A micro Java/Scala http server to share files on the local network
Usage: jmhttp [OPTIONS] ... [[DIRECTORY] | [URL:DIRECTORY] [URL:DIRECTORY] ...]
#=============================================
$ jarget pj-run -- --version
jmhttp - v1.3
- Perform release build - the object code is bundled with all dependencies and the scala runtime library.
$ jarget pj-release -h
Compile project building uber jar in executable wrapper.
-
USAGE: $ jarget pj-release
OPTIONS:
-file=<FILE>, -f Project file. (default build.conf)
-verbose, - Turn verbosity on.
-exe=<EXE>, -e Executable wrapper - [empty, uexe, wcli, wgui] - default (empty)
-show, - Show project configuration before building.
-output=<FILE>, -o Output file, default <FILE> without extension + .sh or .exe.
# Build uber jar ready to use
$ jarget pj-release
Built file: ./bin/jmhttp-release.jar
$ java -jar bin/jmhttp-release.jar --version
jmhttp - v1.3
# Build uber jar embed in Unix shell script (non native executable)
$ jarget pj-release -exe=uexe
Built file: ./bin/jmhttp-release.sh
$ bin/jmhttp-release.sh --version
jmhttp - v1.3
# Build uber jar embedded in Windows console native executable (.exe)
$ jarget pj-release -exe=wcli
Built file: ./bin/jmhttp-release.exe
# Build uber jar embedded in Windows GUI native executable (*.exe)
$ jarget pj-release -exe=wgui
Built file: ./bin/jmhttp-release.exe
$ file bin/jmhttp-release.exe
bin/jmhttp-release.exe: PE32 executable (GUI) Intel 80386, for MS Windows
Command help:
$ jarget utils
General utilities helpers for platform information and debugging.
Actions:
+ env - Show environment variables
+ env <var> - Show a given environment variable.
+ prop - Show java properties.
+ prop <var> - Show a given a java property.
+ path - Show path variable
+ info - Show platform information.
Example: $ jarget utils info
Usage: utils <ACTION>
$ jarget utils -env
On Linux:
$ jarget utils env
Environment Variable Value
------------------------ --------------------------------------------------
PATH /usr/local/sbin:/usr/local/bin:/usr/bin:/usr/li...
XAUTHORITY /home/archbox/.Xauthority
LC_MEASUREMENT pt_BR.UTF-8
LC_TELEPHONE pt_BR.UTF-8
GDMSESSION xfce
XDG_DATA_DIRS /usr/local/share:/usr/share
LC_TIME pt_BR.UTF-8
... ... ... ...
NLSPATH /usr/dt/lib/nls/msg/%L/%N.cat
QT_QPA_PLATFORMTHEME qt5ct
XDG_RUNTIME_DIR /run/user/1001
XDG_VTNR 7
HOME /home/archbox
------------------------ --------------------------------------------------
On Windows:
C:\Users\archbox\Desktop>java -jar jarget utils env
Environment Variable Value
------------------------- --------------------------------------------------
USERDOMAIN_ROAMINGPROFILE DESKTOP-2TJVI2H
LOCALAPPDATA C:\Users\archbox\AppData\Local
ChocolateyLastPathUpdate Thu Feb 15 06:11:43 2018
PROCESSOR_LEVEL 6
USERDOMAIN DESKTOP-2TJVI2H
LOGONSERVER \\DESKTOP-2TJVI2H
JAVA_HOME C:\Program Files\Java\jdk1.8.0_162
PROMPT $P$G
SESSIONNAME Console
ALLUSERSPROFILE C:\ProgramData
PROCESSOR_ARCHITECTURE AMD64
PSModulePath C:\Program Files\WindowsPowerShell\Modules;C:\W...
SystemDrive C:
=ExitCode 00000000
OneDrive C:\Users\archbox\OneDrive
=C: C:\Users\archbox\Desktop
APPDATA C:\Users\archbox\AppData\Roaming
USERNAME archbox
... . .. ... . .. .. . .. . ..
Path C:\Windows\system32;C:\Windows;C:\Windows\Syste...
PATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WS...
OS Windows_NT
COMPUTERNAME DESKTOP-2TJVI2H
PROCESSOR_REVISION 4e03
CLASSPATH .;
CommonProgramW6432 C:\Program Files\Common Files
ComSpec C:\Windows\system32\cmd.exe
ProgramData C:\ProgramData
... . .. ... . .. .. . .. . ..
windir C:\Windows
=:: ::\
------------------------- --------------------------------------------------
$ jarget utils -path
On Linux:
$ jarget utils -path
/usr/local/sbin
/usr/local/bin
/usr/bin
/usr/lib/jvm/default/bin
/usr/bin/site_perl
/usr/bin/vendor_perl
/usr/bin/core_perl
/home/archbox/opt/java/bin
/home/archbox/opt/scala-2.11.8/bin/
/home/archbox/bin
... ... ... ...
On Windows:
C:\Users\archbox\Desktop> java -jar jarget utils path
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0\
C:\ProgramData\chocolatey\bin
C:\Program Files\Java\jdk1.8.0_162\bin
C:\Users\archbox\AppData\Local\Microsoft\WindowsApps
$ jarget utils -prop
Show all Java properties from System.getProperties().
On Linux:
$ jarget utils prop
Java Property Value
----------------------------- --------------------------------------------------
java.runtime.name OpenJDK Runtime Environment
sun.boot.library.path /usr/lib/jvm/java-8-openjdk/jre/lib/amd64
java.vm.version 25.141-b15
java.vm.vendor Oracle Corporation
java.vendor.url http://java.oracle.com/
path.separator :
java.vm.name OpenJDK 64-Bit Server VM
file.encoding.pkg sun.io
user.country US
sun.java.launcher SUN_STANDARD
sun.os.patch.level unknown
java.vm.specification.name Java Virtual Machine Specification
user.dir /home/archbox/Documents/projects/jarget.scala
java.runtime.version 1.8.0_141-b15
java.awt.graphicsenv sun.awt.X11GraphicsEnvironment
java.endorsed.dirs /usr/lib/jvm/java-8-openjdk/jre/lib/endorsed
os.arch amd64
java.io.tmpdir /tmp
line.separator
java.vm.specification.vendor Oracle Corporation
os.name Linux
sun.jnu.encoding UTF-8
java.library.path /usr/java/packages/lib/amd64:/usr/lib64:/lib64:...
java.specification.name Java Platform API Specification
java.class.version 52.0
sun.management.compiler HotSpot 64-Bit Tiered Compilers
os.version 4.9.31-1-MANJARO
user.home /home/archbox
user.timezone
java.awt.printerjob sun.print.PSPrinterJob
file.encoding UTF-8
java.specification.version 1.8
java.class.path /home/archbox/bin/jarget
user.name archbox
java.vm.specification.version 1.8
sun.java.command /home/archbox/bin/jarget -system prop
java.home /usr/lib/jvm/java-8-openjdk/jre
sun.arch.data.model 64
user.language en
java.specification.vendor Oracle Corporation
awt.toolkit sun.awt.X11.XToolkit
java.vm.info mixed mode
java.version 1.8.0_141
java.ext.dirs /usr/lib/jvm/java-8-openjdk/jre/lib/ext:/usr/ja...
sun.boot.class.path /usr/lib/jvm/java-8-openjdk/jre/lib/resources.j...
java.vendor Oracle Corporation
file.separator /
java.vendor.url.bug http://bugreport.sun.com/bugreport/
sun.io.unicode.encoding UnicodeLittle
sun.cpu.endian little
sun.cpu.isalist
----------------------------- --------------------------------------------------
On Windows:
C:\Users\archbox\Desktop>java -jar jarget utils prop
Java Property Value
----------------------------- --------------------------------------------------
java.runtime.name Java(TM) SE Runtime Environment
sun.boot.library.path C:\Program Files\Java\jdk1.8.0_162\jre\bin
java.vm.version 25.162-b12
java.vm.vendor Oracle Corporation
java.vendor.url http://java.oracle.com/
path.separator ;
java.vm.name Java HotSpot(TM) 64-Bit Server VM
file.encoding.pkg sun.io
user.country US
user.script
sun.java.launcher SUN_STANDARD
sun.os.patch.level
java.vm.specification.name Java Virtual Machine Specification
user.dir C:\Users\archbox\Desktop
java.runtime.version 1.8.0_162-b12
java.awt.graphicsenv sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs C:\Program Files\Java\jdk1.8.0_162\jre\lib\endo...
os.arch amd64
java.io.tmpdir C:\Users\archbox\AppData\Local\Temp\
line.separator
java.vm.specification.vendor Oracle Corporation
user.variant
os.name Windows 10
sun.jnu.encoding Cp1252
java.library.path C:\Program Files\Java\jdk1.8.0_162\bin;C:\Windo...
java.specification.name Java Platform API Specification
java.class.version 52.0
sun.management.compiler HotSpot 64-Bit Tiered Compilers
os.version 10.0
user.home C:\Users\archbox
user.timezone
java.awt.printerjob sun.awt.windows.WPrinterJob
file.encoding Cp1252
java.specification.version 1.8
java.class.path jarget
user.name archbox
java.vm.specification.version 1.8
sun.java.command jarget utils -prop
java.home C:\Program Files\Java\jdk1.8.0_162\jre
sun.arch.data.model 64
user.language en
java.specification.vendor Oracle Corporation
awt.toolkit sun.awt.windows.WToolkit
java.vm.info mixed mode
java.version 1.8.0_162
java.ext.dirs C:\Program Files\Java\jdk1.8.0_162\jre\lib\ext;...
sun.boot.class.path C:\Program Files\Java\jdk1.8.0_162\jre\lib\reso...
java.vendor Oracle Corporation
sun.stderr.encoding cp437
file.separator \
java.vendor.url.bug http://bugreport.sun.com/bugreport/
sun.io.unicode.encoding UnicodeLittle
sun.cpu.endian little
sun.stdout.encoding cp437
sun.desktop windows
sun.cpu.isalist amd64
----------------------------- --------------------------------------------------
$ jarget utils expath <program>
$ jarget utils expath java
/usr/bin/java
$ jarget utils expath jarget
/home/archbox/bin/jarget
- jarget utils -info
Output on Linux:
$ jarget utils info
Operating System = Linux
Operating System Version = 4.14.16-200.fc26.x86_64
Operating System Architecture = amd64
Number of processors = 4 cores
Processor endianess = little
OS Path Separators and File Encoding
- path.separator = ':'
- file.separator = '/'
- line.separator = '\n' - LF
- file.enconding = UTF-8
Java Runtime
- java.vm.specification.version = 1.8
- java.runtime.version = 1.8.0_161-b14
- java.vm.name = OpenJDK 64-Bit Server VM
- java.home = /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.161-0.b14.fc26.x86_64/jre
Output on Windows 10:
C:\Users\archbox\Desktop>java -jar jarget utils info
Operating System = Windows 10
Operating System Version = 10.0
Operating System Architecture = amd64
Number of processors = 1 cores
Processor endianess = little
OS Path Separators and File Encoding
- path.separator = ';'
- file.separator = '\'
- line.separator = '\r\n' - CRLF
- file.enconding = Cp1252
Java Runtime
- java.vm.specification.version = 1.8
- java.runtime.version = 1.8.0_162-b12
- java.vm.name = Java HotSpot(TM) 64-Bit Server VM
- java.home = C:\Program Files\Java\jdk1.8.0_162\jre