Importing source code into Eclipse

Dung Le edited this page May 4, 2015 · 25 revisions

Downloading Eclipse

We recommend that you use the Eclipse IDE for Java EE Developers. Make sure you grab the correct 32-bit or 64-bit version, depending on your machine. We also strongly suggest using JDK 7 (i.e., version 1.7) for Eclipse.

(Note: OBA 1.1.13 and higher are compatible with both Java 6 and 7, while OBA 1.1.11 and earlier are only compatible with Java 6).

Setting Up Eclipse

Plugins

Before getting started, you'll need to have a few Eclipse plug-ins installed to help with development.

(Note: The Eclipse JAVA EE IDE https://www.eclipse.org/downloads/index-developer.php?release=kepler should have all plugins you need for this project included except for google plugins for eclipse kepler, so use eclipse IDE software install feature in the help dropdown menu -> Install new software, and add this link to available site (google plugins for eclipse kepler - https://dl.google.com/eclipse/plugin/4.3 - https://dl.google.com/eclipse/plugin/4.3), then install it. To know what components you will need specifically for this project read on).

Specifically, you'll need:

  • A git plugin—a popular choice is EGit
  • The Eclipse Maven plugin—m2e
  • Maven Integration for WTP
  • To deploy the OBA webapp and see the main map-based webpage, you'll also need the Google Web Toolkit plugins and SDK. When installing in Eclipse, make sure you install the "Google Plugin for Eclipse", the "GWT Designer for GPE", and the "SDKs->Google Web Toolkit".
  • Web Standards Tools (WST) plugins—Part of Eclipse's Web Tools Project. These plugins don't need to be installed if you're using the Java EE Developers version of Eclipse, since they're included by default.

You can use the normal Eclipse HelpInstall New Software... process to install these plug-ins.

Config

To make sure Eclipse is using the JDK you want, you can edit your eclipse.ini file to specify the VM it will use. Add the path to the JDK you want to use to your eclipse.ini file, BEFORE the -vmargs line:

-vm

C:/Program Files/Java/jdk1.6.0_27/bin/javaw.exe

...or whatever the path to your JDK is.

We recommend that you show the Eclipse Error Log in your view (Window->Show View->Other->General->Error Log) so you can see the full description of any errors generated by Eclipse and its plugins (i.e., not generated by the OneBusAway code itself).

We also recommend that you expand the capacity of the output Console in Eclipse so you can see the full output of the OneBusAway applications (otherwise, it will only show the last X number of lines). Do this via Window->Preferences->Run/Debug->Console, and uncheck "Limit console output" window" (or increase console buffer size). Just be sure to clear the console occasionally with the button in the Console view to avoid chewing up extra memory.

Finally, we recommend that you configure Eclipse to show line numbers, so its easier to track down trouble-some errors.

Checking Out the Source from Github

We recommend that you check it out to a folder close to the root of your hard drive and without any spaces in the name of the folder path (i.e., C:\oba) - long paths and spaces in folder names can cause headaches later. Keep this in mind in step #5 below.

  1. Switch to the Git Repository Exploring perspective in Eclipse.

  2. Click Clone a Git Repository and type the URI https://github.com/OneBusAway/onebusaway-application-modules.git (or the GitHub URI for whatever repository you're interested in). (Make sure you check out the code with the "secure" (https) URL!)

  3. The Host and Repository path fields should populate automatically. Click Next >

  4. Keep the master branch ticked and untick the other checkboxes. Click Next >

  5. Make any changes you wish in the Local Destination dialogue (remember - short paths close to root and without spaces are recommended), and click Finish

  6. Wait for the repository to be cloned—this may take a couple of minutes

  7. You will likely want to check out a particular tag, rather than the head. At the time of writing, 1.0.7 was the latest stable release, but you should check the download page to see if this is still current. Then:

    • Right-click the repository and select Switch ToOther...
    • Select Tagsonebusaway-application-modules-1.0.7 (or whatever)
    • Click Checkout
  8. In Eclipse Indigo, right-click the repository and select Import Maven Projects.... In Eclipse Juno (and Lunar), there is no appropriate option when right-clicking the repository, so select FileImportMavenExisting Maven Projects and select the Git download directory.

  9. Select the projects you want—you will probably want all of them. Optionally, add them to a working set (Working sets group elements for display in views or for operations on a set of elements.). Click Finish.

  10. Wait for the projects to be imported, and the indexing to finish.

Importing Existing Source into Eclipse (when checking out source code using an external tool)

If you have already checked out the OneBusAway source code using an external tool, such as the Git command line, you can easily import the OneBusAway source into Eclipse. Under the menu option FileImport, browse to the GeneralMaven Projects element:

Maven Project Import

Browse to the root folder of the source tree and then select all the projects of interest:

Maven Project Import

The Result

When everything works correctly, you should see each OneBusAway Maven module checked out as an individual Eclipse project in your workspace:

Project Listing

Note that on initial checkout, it may take a while to initially build all the projects in your workspace. In the background, the Maven plug-in is downloading all the project dependencies (there are a quite a few). This bulk download only happens once.

Update:

In eclipse Luna and oba 1.1.13, after a checkout finished, i got 2 errors (red cross circles on onebusaway-phone-webapp and onebusaway-msm-webapp) - it says 'The superclass “javax.servlet.http.HttpServlet” was not found'. Somehow these jar files / libraries are missing from the build path of these versions. So modify and add them in the pom.xml files of the 2 projects/modules like below.

*pom.xml of onebusaway-phone-webapp, under section: <name>onebusaway-phone-webapp</name><description>This is a simple webapp wrapper around the phone server to assist in startup and shutdown using the webapp container</description>

<dependencies>
    <dependency>
        <groupId>org.onebusaway</groupId>
        <artifactId>onebusaway-phone</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

and

*pom.xml of onebusaway-sms-webapp, under section: <name>onebusaway-sms-webapp</name>

<dependencies>
    <dependency>
        <groupId>org.onebusaway</groupId>
        <artifactId>onebusaway-presentation</artifactId>
        <version>${project.version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

There is still 2 more errors but the same type of error, i have on onebusaway-presentation module/project. It says 'The method getTextContent() is undefined for the type Node' this is because of the order of the library/environment in build path being used. To solve it: You need to go to Properties for the project in eclipse. Then select "Java Build Path" and tab "Order and Export". Here you can arrange the order of dependencies. Ensure that your JRE is higher up then Maven Dependencies.

What's next?

Check out the OneBusAway Developer Guide to configure and run your instance of OneBusAway.

Troubleshooting

Have problems? Check out our Troubleshooting page to see if we have a known solution.