Skip to content

Instantly share code, notes, and snippets.

@lpapailiou
Last active July 11, 2021 10:04
Show Gist options
  • Save lpapailiou/d4d63338ccb1413363970ac571aa71c9 to your computer and use it in GitHub Desktop.
Save lpapailiou/d4d63338ccb1413363970ac571aa71c9 to your computer and use it in GitHub Desktop.

Java repository handling

Table of Contents

  1. Download from github
  2. Import to IDE
  3. Build jar
  4. Run application
  5. Troubleshoot

Download from github

Copy the root url of a repository and include it to following command:

git clone https://github.com/<user-name>/<repository-name> <your-target-path>

Please note that git must be installed to run this command.
Alternatively, download as compressed folder and unpack locally.

Import to IDE

How to import to Intellij IDE

  1. Go to File > New
  2. Pick Maven > Project from Existing Sources...
  3. Now, navigate to the directory you cloned it to
  4. Select the pom.xml file and click OK
  5. The project will be opened and build

How to import to Eclipse IDE

  1. Go to File > Import
  2. Pick Maven > Existing Maven Project
  3. Now, navigate to the directory you cloned it to
  4. Pick the root directory and click Finish
  5. The project will be opened and build

Build jar

Build Jar in Intellij IDE

  1. Go to File > Project Structure...
  2. Go to the Artifacts tab and add a new Jar > From module with dependencies entry
  3. Select the main class
  4. Click Ok twice
  5. Go to Build > Build Artifacts...
  6. Select Build
  7. The Jar file is now added to the target folder within the project structure

Build Jar in Eclipse IDE

  1. Right click on the project
  2. Choose Export
  3. Go to Java > Runnable JAR file
  4. Click Next
  5. Launch configuration: choose the main class
  6. Export destination: the place you want to save the jar
  7. Choose Extract required libraries into generated JAR
  8. Click Finish to start the Jar generation

Run application

Within the IDE

You can directly run it within the IDE. Refer to support page of the specific IDE.

From a jar file

Download the jar file from the releases or build it yourself in the IDE.
Start the application with following command in your terminal:

java -jar <filename>.jar <optional-arguments> 

Please note that the java path and java home variables must be set. Also note that the command must be run from the same directory where the jar file is located, otherwise the relative or full path must be added as prefix of the jar file.

In case of an application with graphic user interface, you may start the application by double clicking on the jar file.

Troubleshoot

Jar file does not run

Make sure you did set the java path and java home variables.
Try to start it from the terminal. There, you might get more specific error messages.

DPI scaling

In case you experience weird UI behavior (e.g. buttons look weird), it may be a DPI scaling issue known to occur with Windows 10 notebooks. To fix it, do following steps:

  1. Find the java.exe the application is running with (check Task Manager)
  2. Rightclick on the java.exe and go to Properties
  3. Open the Compability tab
  4. Check Override high DPI scaling behavior
  5. Choose System for Scaling performed by:
  6. Rerun the application
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment