« Project bashj : a bash mutant with java support » : différence entre les versions
Aucun résumé des modifications |
Aucun résumé des modifications |
||
Ligne 13 :
This page is an introduction to bashj, with general notes and installation guide.
There is also a '''[[Bashj_programming_guide|<span style="background-color:#E6E6FA;">
To bash developers, bashj brings
|
Version du 20 juin 2018 à 13:25
What ?
The bashj project is hosted on sourceForge. bashj is an extended bash allowing to use java libraries, methods and source code from bash scripts.
The bashj code combines
- java performance and readability
- bash power and versatility
-> Current version 0.994 (june 2018) is still a beta release... Release 1.0 expected july 2018 !
This page is an introduction to bashj, with general notes and installation guide.
There is also a bashj programming guide page.
To bash developers, bashj brings
- Readability in the java segment (OO style coding)
- JVM efficiency for CPU intensive components
- modular extensibility using java packages
- floating point (double) values variable and evaluation functions
- Math tools
- Swing UI tools
- Inter process tools between multiple bash process (and java process)
- Host registry
- ...
Why ?
Java and bash are often partners in software projects.
Personnally I used both of them widely. Being rather lazy, I tried to minimize the number of necessary techonologies in my projects. These two covered 99% of my needs together. Java is perfect to translate concepts into software. But bash is necessary for various OS level tasks, like process control, deployment ... But I was frequently disappointed by the incapacity to reuse java results and expertise within scripts (this was only possible with heavy java process launching, and main() entry points). I was also frustrated by the strange and numerous coding conventions necessary to perform simple bash tasks. So I decided to set up and use this bashj tool.
Since bashj appeared to offer significant benefits, I decided to make it publicly available.
In terms of genetics, consider bashj as a bash mutant, whose genome has been loaded with wide portions of the java genome.
Their possible interactions are numerous but limited in terms of integration.
With this project, any script is given the capacity to quickly and directly call java methods without creating new OS processes.
How ?
A bashj server (a java background process) communicates with bash scripts (considered as clients).
Dedicated functions are internally defined, and used from bash script clients to request server actions.
The communication uses mainly TCP connections.
This may be also be seen as a kind of bash preprocessor : bash itself is called by the bashj process.
Requirements and limitations
- bash scripts only (version.4.*+)
- Linux only (kernel 4.*+)
- java JDK (9+) (JRE is not enough)
- only public static methods (and public static fields) may be called
- only methods with primitive types (including String) as parameters and return value (neither array, nor collections). Varargs are supported by bashj.
- no embedded invocations of java methods
- These characters ® © have specific usage within bashj and may not be used in bashj sources
Installation
Follow carefully these steps:
- create a directory : sudo mkdir -m=777 /var/lib/bashj/
- download from sourceForge the bashjInstall-version.jar installation file and move it in this directory
- running a bash session, go to the installation directory : cd /var/lib/bashj/
- run : jar xf bashjInstall-version.jar
- run : chmod +x bashj
- run : sudo ./bashj -install
For the uninstallation:
- cd
- sudo /var/lib/bashj/bashj -uninstall
Check, try and test
Various bashj scripts examples are in /var/lib/bashj/example/.Open a bash terminal window and type the following commands to discover bashj's actions.
The same may be realized for all example scripts.
It is suggested to try, copy, adapt these examples scripts.
Configuration
No configuration is necessary.
However it is possible for the user to put various jar files under the jarlib/ directory.
All public static methods and all public static fields defined in these classes will be available in the bashj interpreter.
They should be called as indicated in the programming guide..
Annexes
Support
Please contact fil@gonze.org for support, remarks, suggestions,...
bashj interactive commands
The bashj script may be called as interpreter, or interactively for various actions. Use bashj -help to see this:
-help
-install
-uninstall
-status : server status
-stop : stops the server
-restart : restart server
-out : show server stdOut
-err : show server stdErr
+methods <filter> : lists methods accessible to bashj clients
+fields <filter> : lists fields accessible to bashj clients
example: bashj "Math.hypot(3.0,4.0)"
Installed Files
The files are installed under /var/lib/bashj/, and include:
- bashjInstall.jar (a jar containing all bashj required files)
- bashj (the central script, including the command interpreter - a link is created in /usr/bin)
- bashj.wrk (auxiliary script)
- bashjServer.jar (a jar containing the compiled java class bashj.server.class)
- README (a readme file - short intro to this wiki page)
- classes/ , bashSrc/ and bashjSrc/ (subdirectories with transient working contents)
- jarlib/ (a subdirectory with the jars choosen by the user to make the involved classes available to bashj)
- example/ (a subdirectory with various example scripts (executable files))
Tech notes
The execution time of bashj is excellent due to
- TCP efficiency
- in-memory dynamic java compiling
- cache-based java class loading
- JVM global efficiciency
Speed notes
Simple tests (on a 2018 standard machine) indicate that a basic java method call requires around 1 msec. This probable depends on TCP config parameters.
The startup time for a bashj script is around 25 msec.
For calls involving heavy CPU load, the execution delay is exactly the same as in a direct JVM.
Future Improvements
- ? Allow more than 1 occurence of calls per line for given method
- ? Create a installable package for debian distribs.
- ? Organize the bashj server as a Linux service