-
Notifications
You must be signed in to change notification settings - Fork 1k
Getting started with OTP in Netbeans
IMPORTANT CAVEAT:
Netbeans 7.1 is the first version of Netbeans to have native Git support. While Git functionality seems to work fine, there are always risks to being an early adopter of technology. If you have problems with Git in Netbeans, check out their issues page to see if the problem is a known issue.
We recommend that you download and install JDK 6 (i.e., Java 1.6 development kit) prior to installing Netbeans. OTP won't compile properly in JDK 7 (i.e., Java 1.7), so its best if you configure Netbeans to use JDK 6 when you're installing Netbeans.
Netbeans 7.1 is the first version of Netbeans to have native Git support, so you'll need to grab the latest version of Netbeans from the Netbeans home page. We have confirmed that OTP works in the complete Netbeans download package (right-most download option that includes all features), but it should work in the Java EE version as well. Apache Tomcat and Glassfish application servers are both bundled with Netbeans, so you don't need to download these separately.
Double-click on the file you just downloaded, and you'll kick off the install wizard. You'll need to choose the "Custom" installation option if you want to install Apache Tomcat 7 along with Netbeans. By default, only the Glassfish Java Application Server 3.1 will be installed with Netbeans. OTP can run in both Glassfish and Tomcat 7.
Choose to use JDK 6 (default install location of something like "C:\Program Files\Java\jdk1.6.0_22") for Netbeans. If you accidentally choose JDK 7, don't panic, since you can edit the Netbeans config file after it installed and change the default JDK by opening the file C:\Program Files\NetBeans 7.1 Beta\etc\netbeans.conf, and change to install location of JDK 1.6.
The important thing is that you set up Netbeans to use JDK 6 by default before cloning the OTP repository in the next steps.
OTP is versioned using Git and its build process and dependencies are managed by Maven, but both Git and Maven support is native in Netbeans, so you don't need to install any plugins. So, we can get straight to grabbing the source code by cloning the OTP Git repository (i.e., copying the OTP repository to your PC).
To clone the Git repository, click on "Team->Git->Clone..." in Netbeans as is shown below.
Then, enter the URL https://github.com/openplans/OpenTripPlanner.git
(or ssh://[email protected]/openplans/OpenTripPlanner.git
if you have a personal public key registered at Github). You'll also need to enter your GitHub username and password here if you want to contribute code back to the project, or just leave them blank for anonymous access.
Click "Next", then check the "master" branch, and click "Next" again.
Here you will need to select a path to store the cloned repository on your hard drive. IMPORTANT: you should choose a folder with as short a path (i.e., closest to the root) as possible, and WITHOUT any spaces in the folder name. Otherwise, you'll have problems later when you try to build the project (Netbeans will say it can't find certain files). The folder we use in the sample below is 'C:\OTPfiles'. This will create a cloned repository in 'C:\OTPfiles\OpenTripPlanner'. Now, click "Finish", and wait a while for the code to be downloaded from the Github repository.
After the download is complete, Netbeans will ask you if you want to opened the downloaded projects, and click "Ok".
Once you clone the OTP repository and choose to open downloaded projects, you should see the main OpenTripPlanner maven project in the left pane in Netbeans. Expand this project node, and "Modules" in the next set of nodes, and you should see the entire set of OTP projects.
Rght-click on the "opentripplanner-api-webapp" project, and select "Open Project". Do the same for "opentripplanner-webapp", and, if you want to build your own graphs, the "opentripplanner-graphbuilder" project as well.
Don't build the projects yet, since we need to change a few things next, as discussed in the next section, before things will compile correctly.
We need to change a few things in the code to make OTP compile without problems in Netbeans.
We need to edit the web.xml for opentripplanner-api-webapp to make the project deploy correctly to Apache 7 and Glassfish.
Drill down into the opentripplanner-api-webapp project under Web Pages->WEB-INF to find web.xml, and double-click to open the file.
Then, switch order of the below elements in web.xml so they match the order below (same order as in above screenshot):
<init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>org.opentripplanner</param-value> </init-param>
<init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>com.sun.jersey.samples.jsonfromjaxb</param-value> </init-param>
Next, we need to make sure that opentripplanner-api-webapp will be deploying to the correct context path.
For opentripplanner-api-webapp, under Properties->Run->Context Path, paste /opentripplanner-api-webapp. The screenshot below shows this.
You will need to change the context path for opentripplanner-webapp as well (Properties->Run->Context Path in that project), with /opentripplanner-webapp as the Context Path (otherwise both may deploy to root context path).
Next, we need to tell Netbeans not to launch the browser for the opentripplanner-api-webapp project, since there isn't a page to launch. To do this, go to the opentripplanner-api-webapp, right-click, and under Properties->Run uncheck Display Browser on Run.
You're ready to build your projects, so proceed to the next section.
Now, its finally time to build your projects!
The first time you build everything try to do it on a high-speed internet connection, since Maven will download all the dependencies, which could take a very long time on a low-speed connection.
Go back to the main OpenTripPlanner Maven project at the top of the upper left Projects pane, right-click on the main project, and select Clean & Build.
This triggers Maven to download all the dependencies for the project, so the first time you run this it will take a while for this step (go grab a snack). After all Maven dependencies have downloaded, Netbeans will run all the tests to verify everything is set up properly, which also takes a little while.
If all goes well, you'll have a compiled version of OTP when the build completes successfully! If the build fails, check to be sure you've completed all the above tweaks, including having no spaces in the folder name containing OTP on the hard drive, and make sure you're compiling the projects using JDK 1.6 (check via Properties->Build->Compile). If you're still having problems, check out our Troubleshooting page.
Next, you need to get a graph together to give OTP data to route on.
You'll need to build a graph to be used in OpenTripPlanner so it has multimodal data for a transportation network. Go to the GraphBuilder page to put a graph together, since this is pretty much the same for Netbeans and Eclipse, and then come back here once you have a Graph.obj file to work with.
Once you have a Graph.obj for OTP to use for routing, you'll need to tell the opentripplanner-api-webapp where it can find this file on your hard drive. This configuration is the same for both Netbeans and Eclipse, so follow the directions on the Configuring the opentripplanner-api-webapp page, then come back here to get the web server started in Netbeans.
OTP should be easily deployable to either Apache Tomcat 7 or Glassfish once you get to this point. Before starting the server, you may want to re-build the projects again (click main OpenTripPlanner maven project at top of left panel, right-click, Clean and Rebuild) before starting the server to make sure all your above changes have been included in the current build.
In the following instructions we focus on step-by-step instructions for Glassfish, since the Eclipse instructions focus on Tomcat. Glassfish also has enterprise features for high availability and scalability, a web management console, and other features that Tomcat does not, which may be of interest.
We'll start up Glassfish by going to the Services tab in the left main Netbeans pane, and right click on Servers->Glassfish node, and click Start. The Output pane in the lower-right corner should open up a Glassfish tab, and you'll start seeing the server output, as shown below.
Note that the web applications will deploy to port 8080 by default, and the Glassfish web admin console (which you'll access in the next step) is available at port 4848 by default.
Next, we need to make sure there is enough memory to load the OTP Graph file (Graph.obj), which can be a pretty huge file. We'll access the Glassfish web admin console by going to the Services tab in the left main Netbeans pane, and right click on Servers->Glassfish node and select View Domain Admin Console. This will launch your browser to the web admin page, which will take a few moments to load.
In the Glassfish Domain Admin Console in your browser, click on “Configurations->server-config->JVM arguments” node in left column. Under “VM Options” tab, find line that has “-Xmx512m” and change to“-Xmx2048m”, as shown below.
Save the setting with the Save button in upper right hand corner of the same panel, then click on the “Restart Required” link in the upper left corner of page, then “Restart” button to restart the server with the new memory settings. Be patient while it takes a minute to restart.
Now, we're ready to deploy the OTP web apps to Glassfish, which we'll do in the next steps.
To deploy the OTP web app projects to Glassfish, you need to tell Netbeans that Glassfish should be the target for running opentripplanner-api-webapp and opentripplanner-webapp. To do this, for each project right-click and go to Properties, then the Run node and select Glassfish in the Server combo box.
To deploy the web API project to Glassfish, right-click on the opentripplanner-api-webapp project, and click Run. It might take some time for the app to deploy, since it needs to load up the graph.
After the opentripplanner-api-webapp project deploys successfully, then deploy opentripplanner-webapp using the same process. If all goes well, your OTP instance should be available at http://localhost:8080/opentripplanner-webapp/.
NOTE: After the projects are deployed, Netbeans may automatically launch a browser to show you the link, but it may launch to the incorrect URL. The correct URL is: http://localhost:8080/opentripplanner-webapp/)
Congrats, you're done!
If you expect to submit patches to OTP, please download the GeoTools format specification and apply it to the OTP projects in Netbeans.
TODO - need to add code style instructions for Netbeans
This will keep code formatting consistent, and improves readability by avoiding a mixture of tabs and spaces in the code.
- Check out our Troubleshooting page
unless you are intentionally working with legacy versions of OpenTripPlanner. Please consult the current documentation at readthedocs