How to Get and Build jung2

Maven

We've set up JUNG to build using maven2. ( http://maven.apache.org )

  1. Download and install maven2 from maven.apache.org at http://maven.apache.org/download.html . At time of writing, the latest version was maven-2.0.4
  2. Install the downloaded maven2 (there are installation instructions here: http://maven.apache.org/download.html#Installation).
  3. Follow the installation instructions and confirm a successful installation by typing 'mvn --version' in a command terminal window.

Get the jung2 code from CVS

If you are a developer:

    export CVS_RSH=ssh
    cvs -z3 -d:ext:your-login@jung.cvs.sourceforge.net:/cvsroot/jung co -P jung2

If you are not a developer:

    cvs -z3 -d:pserver:anonymous@jung.cvs.sourceforge.net:/cvsroot/jung co -P jung2

(see below for eclipse instructions if you would prefer to checkout jung2 using eclipse)

    cd jung2
    mvn install

This should build the sub-projects and run unit tests. During the build process, maven downloads code it needs from maven repositories. The code is cached in your local repository that maven2 creates in your home directory ($HOME/.m2/repository).

Remember, maven2 needs to download code from the internet, especially the first time it is used on a new project. If the download of something is interrupted, the build may fail. If so, just run it again (and again) and it should eventually succeed. Once all the files are cached in your local maven repository, the build process will be faster.

To prepare jung2 to use with eclipse, run the following maven command:

     mvn eclipse:eclipse

which will generate the .classpath and .project files for eclipse.

The .classpath file will make reference to a M2_REPO variable, which you must define in eclipse, so that M2_REPO points to your local repository. You can do that in eclipse by bringing up project properties and adding the variable M2_HOME, or you can run the following command to have maven set the variable for you:

     mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo 

If that does not work, you'll need to open one of the project's Properties and use the add variables button in the libraries tab.

To load jung2 in eclipse, you need to overcome an eclipse limitation: Eclipse projects cannot contain subprojects. (Jung2 contains 6 sub-projects). The common work-around is to make eclipse think that each sub-project is a top-level project.

The most common way to proceed is as follows:

Add each subproject (jung-api, jung-graph-impl, jung-visualization, jung-algorithms, jung-samples, ...) as a top-level project in eclipse, each with its own classpath dependencies.

One approach is to use the eclipse feature for importing projects, AFTER mvn eclipse:eclipse has been run as shown above. Simply point the eclipse import project file chooser to the jung2 directory, then check off the list of subprojects that are shown.

Another approach is to manually add each project as follows: In the New Project dialog, select Java Project, then Create project from existing source. Create the new project to point to where you downloaded jung2 and its subprojects. For example, you would create a new project from the existing source in '/where/it/is/jung2/jung-api' and name that project 'jung-api'.

Because you previously ran mvn eclipse:eclipse at the jung2 directory level, the projects will already reference the other projects they depend on (instead of the jar from those projects).

You cannot use jung2 (the parent project) as the eclipse project, as each eclipse project can have only one classpath and one source tree, and you would then have difficulty maintaining the correct dependencies between the sub-projects.

Special cvs checkout instructions using eclipse

If you are unable to use CVS from a command prompt, you may check out jung2 using eclipse. HOWEVER, because of the above stated limitation that eclipse has for nested projects, you must use the following trick:

  1. Create a brand new workspace that you will be using only to check out the project. You will never be using this new workspace to actually work on the project. Let's call it $HOME/checkout_base.
  2. From that workspace, use the eclipse capabilty to check out jung2 from cvs.
  3. Open a command prompt console and change directory to the newly created $HOME/checkout_base/jung2.
  4. Execute this command: mvn eclipse:eclipse . That will build the eclipse project artifacts.
  5. Change eclipse to point to a different workspace (the one that you will actually be working in).
  6. Use the eclipse capability to import projects from your $HOME/checkout_base/jung2 into your new workspace.

Running a Demo

Once you have built everything (preceding instructions), here is a straightforward way to run a demo from the command line:

    cd jung-samples/target/
    tar xvf jung-samples-2.0-dependencies.tar
    java -cp jung-samples-2.0.jar samples.graph.VertexImageShaperDemo?

Return to http://jung.sourceforge.net/pmwiki/index.php/Main/Version2JUNG

Valid XHTML 1.0! Valid CSS!