Giter Club home page Giter Club logo

javahomeshellwrapper's Introduction

JAVA_HOME Shell Wrapper

This is a series of wrapper script for Java, meant to be run by shell. (Currently Bourne Shell only)

Disclaimer

I am by no means a Java developer.

Description

I have to use different Java versions to perform different task, so I'd keep all of the versions installed.
But thing is some OS's (especially some Linux distributions) tend to put all executables of one specific version of Java in somewhere PATH environment variable typically contain, typically /usr/bin.
This place is somewhat unable to be removed because it is shared by some system essentials, unless I make a directory containing the needed executables by myself.

To easily resolve this problem one can just prepend the bin directory of the Java installation to be used afterwards to the PATH environment variable.
But thing is that by doing this one may introduce incompatible executable.
e.g. We originally have Java 8 in PATH and prepend the Java 17 bin directory, the resulting PATH will contain Java 8 unpack200 as well as Java 17 javac, since Java 17 does not come with unpack200.

In macOS and Windows world, one can change the Java version by setting environment variable JAVA_HOME to the directory contains any Java installation.
On macOS it is straightforward since the system includes a series of wrappers which read the value of this environment variable and find the executable there.
This project (or, wrapper scripts) is inspired by the wrappers.
On Windows however, Java should be usually installed by the installer package which does not touch PATH by default.
Although there is no wrapper performing the task macOS does, the executables run on Windows also typically respect the JAVA_HOME environment variable and use corresponding Java installation.
On Linux and other Unix-like system one may install Java from the package source. In this case the behavior is controlled by the system which distributed them.
If the executable is placed in /usr/bin no one can change the behavior without root permission. In this case JAVA_HOME also do not work.

I have searched for the whole GitHub and found no project for doing this task.
Since I think this task should be simple I'd implement it by myself.

Designation

Wraps the java executable series with the scripts in the bin directory in this repository.

When any of the wrapper script is run, following is done:

  1. Search for java (instead of the executable name currently run) in the directory JAVA_HOME environment variable is currently pointing to if set.
  2. If JAVA_HOME is not set or there is no java executable exist there, search for java in directories in PATH environment variable, and find the first one.

If either of the above found a java executable in any path:
Search for the executable currently run in the aforementioned path and exec into it if found, with the arguments passed to wrapper.

If an executable is not find the wrapper script exits with code 127.

Usage

Prepend (Important! not append) the absolute path of bin directory from this repository to PATH.

License

MIT

TODOs

  1. Windows support (run in MSYS2, run Windows Java executable)
  2. Tests (Important for 1.0.0 release. A series of fake Java executable is needed. Maybe it should be in binary form CMake may be involved)
  3. Other shells (cmd is 1st priority but I don't think it's easy for writing logic for it. Important for 2.0.0 release)

javahomeshellwrapper's People

Contributors

fsu0413 avatar

Watchers

 avatar  avatar

javahomeshellwrapper's Issues

Windows support

  • run in MSYS2
  • run in Cygwin

Currently issue is that there is no symlink support in implementations of all of Git for Windows (experimental support), Cygwin installation of git and MSYS2 installation of git.
All these 3 git implementation treats symlinks as regular text files and failed to run scripts except for java (which is the real entry point).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.