GithubHelp home page GithubHelp logo

anderslindgren / installation-home-locator Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 69 KB

Finds out where on the installed machine your project has been installed

Home Page: See the Wiki for more information

Java 100.00%

installation-home-locator's Introduction

Installation Home Locator

Java CI with Maven

Introduction

Welcome to the installation-home-locator!

This is a project written in Java that will help you make it easier to find your installation home directory. I.e. The name of the directory or folder where your program has been installed.

Background

Twice in the past I had to figure this out, so I now finally wrote it down as a more general solution.

Hope it can help anyone else. At least now I know where to find the code the next time the problem arises :-)

Usage

The Installation Home Locator is meant to be used as a utility to drop in to your application. Specially if you are developing a GUI application, you don't know where in the file system your application is finally being deployed.

The HomeLocator will return the directory where your code has been installed.

All this can be achieved with various start scripts in bash or bat-files, but it's more fun doing it in pure Java.

So how do I use this? It's easy! Include the jar file in your directory of third-party jars and add it to your classpath.

In your application you only need to add a few lines (or cram it together on one line if you like):

import java.nio.file.Path;

import se.javatomten.homelocator.*;

public class MyApplication {

    public MyApplication() {
        // Option; Give a relative path to the directory you actually call home.
        // I.e. if the jar file is located in a subdirectory to your home directory, as "lib"
        // You can give a relative path (i.e. "../") as an argument to the Constructor.
        final String relativePath = "../";
        final HomeLocator locator = new HomeLocator(relativePath);
        final Path homeDirectory = locator.getLocation();

        System.out.println("MyApplication is installed in: " + homeDirectory);
    }
}

It is also possible to add another class as a locator class if you have the HomeLocator class in a maven directory.

installation-home-locator's People

Contributors

anderslindgren avatar dependabot[bot] avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

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.