How to use JGraphT as a dependency in your projects

John Sichi edited this page Aug 9, 2018 · 34 revisions

These instructions explain how to use JGraphT as a dependency in your projects. If you are interested in contributing to JGraphT refer to the contributor guidelines instead.

General Instructions

To use JGraphT, starting with version 1.0.0, JDK 1.8 is required at a minimum (earlier versions with less functionality can be used on older JDK's/JRE's). JavaDoc files of the latest release are available online. Version specific javadoc can be downloaded for offline usage from our downloads page. A readme containing basic information to get you started, is bundled with each release.

To use JGraphT as a dependency in your project, follow the instructions for your specific IDE below:

Remember to cite JGraphT in your book, paper, website, technical report if your work relies on JGraphT. This helps us track how JGraphT is used, and acknowledges the work that many JGraphT developers have put into the project.


Developing using Eclipse

These instructions are for Eclipse IDE versions Neon, Oxygen or later.

Use our Maven archetype (preferred)

Use the JGraphT Maven archetype by following our tutorial. Make sure that you have Maven plugin installed in your Eclipse IDE. The simplest way to ensure that is to download the JEE version of Eclipse.

Importing JGraphT through Maven

  1. Open up the Workspace of your Project, else create new Workspace.
  2. Make sure you have Maven plugin installed in your Eclipse IDE.
  3. On the top menu bar, open Window -> Show View -> Other
  4. In the Show View window, open Maven -> Maven Repositories
  5. In the window that appears, right-click on Global Repositories and select Go Into
  6. Right-click on "central (http://repo.maven.apache.org/maven2)" and select "Rebuild Index"
    • In eclipse, this step will take a long time to complete (Consider using Intellij IDE instead...)
  7. Create a new Maven Project (skip this step if you already have an existing project).
    • Go to File -> New -> Other -> Maven Project
    • Use default Workspace location or select an alternative Workspace, Click Next
    • Select maven-archetype-quickstart, Click Next and enter the desired groupID, artifactID, and Click Finish

Note: For the next steps to work, your project must be an Eclipse Maven project! If you created a new Maven Project, you are in good shape. If you opened up an existing project, or created a new Java Project, you must convert your project to a Maven Project. To do this, right-click on you project -> Configure -> Convert to Maven Project -> follow the dialogue menus.

  1. Right-click your project -> Maven -> add Dependency. Fill in the desired information under groupID, artifactID, version. At the very least, you want jgrapht-core:
      <groupId>org.jgrapht</groupId>
      <artifactId>jgrapht-core</artifactId>
      <version>x.y.z</version>
    
    where x.y.z is the desired version. Alternatively, you can use the search menu to search for available jgrapht components. Notice that snapshot versions of JGraphT do not show up in this menu! If you want to use a snapshot version, you need to type the groupId, ArtifactId and version information manually. For more information, refer to the readme

Importing JGraphT as a Jar.

In general it is preferable to download JGraphT through Maven, since this approach will automatically download and manage the necessary dependencies for you.

  1. Download the desired version of JGraphT, and unpack to the desired location, for instance <workspace>/<project_folder>/lib/jgrapht-X.Y.Z where X.Y.Z is the JGraphT version number you downloaded.
  2. Open up the Workspace of your Project, else create new Workspace.
  3. Right Click on Project -> Click Build Path -> Select Configure Build Path...
  4. Under Libraries Tab -> Click on Add External JARs...
  5. Browse to the Unzipped "jgrapht-X.Y.Z/lib".
  6. Select the JARs you want to add to your project. Add the very least, you want to select jgrapht-core.
  7. OPTIONAL: add documentation and sources. Select the drop-down button of any of the dependencies you added. In the Project Structure Screen, select the jgrapht package you added. Select javadoc -> edit -> javadoc URL -> browse -> select the javadoc folder from the unzipped "jgrapht-X.Y.Z" archive. Similarly, to add the source files, select source attachment -> edit -> external location -> external folder -> select the source folder from the unzipped "jgrapht-X.Y.Z" archive.
  8. Click Apply and Close
    • Under Referenced Libraries folder, you can see all the JAR files are imported.

Developing using IntelliJ IDEA

These instructions assume that you are starting a new Java project, or you have an existing java project. Notice that JGraphT requires Java 8.

Importing JGraphT through Maven (preferred)

The general instructions to import a library through maven in IntelliJ can be found here. Additional information about the availability of JGraphT through maven can be found here.

  1. In IntelliJ IDEA, libraries can be defined in the Project Structure dialog. Go to File | Project Structure, or press Ctrl+Shift+Alt+S
  2. To define a project library, select Libraries under the Project Settings section.
  3. Click the green + sign, and select From Maven.
  4. In the Download Library From Maven Repository window, type org.jgrapht into the search bar and hit enter. After the search completes, you can select the drop-down button on the search bar and select the desired library module. In most cases, you want at least the core package: org.jgrapht:jgrapht-core:X.Y.Z, where X.Y.Z is the desired version, e.g. org.jgrapht:jgrapht-core:1.0.1. Next, click ok twice.
  5. OPTIONAL: add documentation. In the Project Structure Screen, select the jgrapht package you added, and click the green + on the right most panel, select the desired *-javadoc.jar and hit ok.
  6. Back in the Project Structure screen, click apply, and ok. You can now use JGraphT in your code. In the Project overview, you can see JGraphT under External Libraries.
  7. OPTIONAL: repeat steps 1-4 to import additional JGraphT modules, e.g. org.jgrapht:jgrapht-io:X.Y.Z.

Importing JGraphT as a Jar.

In general it is preferable to download JGraphT through Maven, since this approach will automatically download and manage the necessary dependencies for you.

  1. Download the desired version of JGraphT, and unpack to the desired location, for instance <project_folder>/lib/jgrapht-X.Y.Z where X.Y.Z is the JGraphT version number you downloaded.
  2. In IntelliJ IDEA, libraries can be defined in the Project Structure dialog. Go to File | Project Structure, or press Ctrl+Shift+Alt+S
  3. To define a project library, select Libraries under the Project Settings section.
  4. Click the green + sign, and select Java. Browse to the location where you unpacked jgrapht, and select the desired package inside the lib folder, e.g. <project_folder>/lib/jgrapht-X.Y.Z/lib/jgrapht-core-X.Y.Z.jar. Next, click ok twice.
  5. OPTIONAL: add documentation. In the Project Structure Screen, select the jgrapht package you added, and click the green + on the right most panel. Select the javadoc folder inside the extracted JGraphT folder and click ok.
  6. Back in the Project Structure screen, click apply, and ok. You can now use JGraphT in your code. In the Project overview, you can see JGraphT under External Libraries.
  7. OPTIONAL: repeat steps 1-4 to import additional JGraphT modules, e.g. org.jgrapht:jgrapht-io:X.Y.Z. Starting with releases after 1.2.0, there is also a 'jgrapht-bundle' jar which rolls together all of the JGraphT libraries together with their dependencies. (Earlier releases provided 'uber' jars for the same purpose.) Use the bundle jar if you want the convenience of having to download/manage dependencies yourself. However, note that the bundle jar is large and may contain much more than you need.

Developing using Netbeans

These instructions are for Netbeans Java SE version 8.2 or above.

Importing JGraphT through Maven (preferred)

  1. Create a new Maven Project (skip this step if you already have a Maven project).
    • Go to File -> New Project (Ctrl-Shift-N)
    • Select Java Application from the Maven category -> Click Next
    • Provide a Project Name and set the Project Location to an appropriate folder on your system.
    • set the desired Maven settings: groupID, Version, Package.
    • click Finish For the next step to work, your project must be a Maven Project. This won't work for a Java Application selected from the Java Category!
  2. Expand your project in the Projects pane, right click on Dependencies -> click Add Dependency...
  3. search for JGraphT in Query field and select the desired dependency, e.g. 1.1.0 [jar] - central from org.jgrapht:jgrapht-core. Alternatively, manually enter the groupID, artifactID, version of the desired dependency in the corresponding fields. Click Add. Under Dependencies, you can see the imported dependencies. For more information, refer to the readme

Importing JGraphT as a Jar.

  1. Download the desired version of JGraphT, and unpack to the desired location, for instance <project_folder>/lib/jgrapht-X.Y.Z where X.Y.Z is the JGraphT version number you downloaded.
  2. Create new Project (skip this if you already have an existing project).
    • Go to File -> New Project (Ctrl-Shift-N)
    • Select Java Application from the Java category -> Click Next
    • Provide a Project Name and set the Project Location to an appropriate folder on your system.
    • click Finish
  3. In the project pane, expand your project, right click Libraries-> add JAR/Folder. Browse to the Unzipped "jgrapht-X.Y.Z/lib" folder and select the JARs you want to add to your project. At the very least, you want to select jgrapht-core. Click OK.
  4. OPTIONAL: add documentation and sources. In the project pane, select the drop-down button next to Libraries. Right-click the JGraphT dependency-> edit. Click the browse button next to javadoc, and select the javadoc folder from the unzipped "jgrapht-X.Y.Z" archive. Similarly, click the browse button next to sources and select the source folder from the unzipped "jgrapht-X.Y.Z" archive. Click OK.

Command Line

If you prefer to work from the command line you can use Maven directly to create a new project.

  1. Issue the following command
mvn archetype:generate -DarchetypeGroupId=org.jgrapht.archetypes -DarchetypeArtifactId=maven-archetype-jgrapht -DarchetypeVersion=1.2.0
  1. Fill in the necessary details about your project.

  2. Start coding!

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.