Tutorial: Participate in a Maven2 based, shared webproject
aus eecoo wiki, der freien Wissensdatenbank
This article covers the following issues:
- setup a connection to a remote Subversion (SVN) repository
- checkout a webproject into your workspace
- compiling and deploying the project locally using Maven2
For installation issues about Maven2, Eclipse and other tools used in this tutorial please refer to the external sites at the end of the article.
Eclipse requirements:
- Eclipse 3.2
- M2 Eclipse plugin (Mergere) from Codehaus: http://m2eclipse.codehaus.org/
- Subclipse Subversion Eclipse plugin from Tigris: http://subclipse.tigris.org/ (update-site: http://subclipse.tigris.org/update)
System requirements:
- Maven2 2.0.4 from Apache: http://maven.apache.org/
- Java 1.5
Inhaltsverzeichnis |
Setup a connection to a remote Subversion repository
To participate in a shared project you have to download the sources at first, this is called "checkout the source". Using Subversion (the modern version of CVS) this checkout can be done either by using the subversion commandline tool or - if you have the Eclipse IDE with the plugins stated above installed - use Subclipse to checkout the source. For simplicity reasons we describe the latter way here.
You need some configuration settings of the project (that is normally found in the development section of the project's website), i.e.:
Location: http://svn.eecoo.net/jaxfaces User: anonymous Password: ******
Note that the URL can also start with "svn://.." which is used by the subversion default server. You should also consider that most repositories are restricted for write access, therefor you typically need a user account with some password.
Having these information in mind and installed Subclipse successfully you can change Eclipse's perspective to "SVN Repository Exploring" by selecting it in the "Window > Open perspective > Other..." dialog as shown below:

In the appearing "SVN Repositories" view you can right click on a blank part of the background and select "New > Repository Location...". In the dialog you have to put in the repository location as given above:

The first time you try to access the server (subversion can store your userdata in [userHome]/subversion/auth/svn.simple/ by checking the "Save password" option in the next dialog) you have to provide your username and password for successfully finishing this process.
Checking out the project
Having set up the repository location you can now check out the project. It is recommended for projects to seperate the repositories workspace into different directories namely "trunk" (containing the latest development code), "branches" (containing out sourced fragments i.e. for bug fixing or experimental developments) and "tags" (containing versions of the code that were just released). If you want you can read more on standard repository layout.
As we want to participate in a project we checkout the trunk, the latest code, of it. Therefor expand the newly created repository location and select the project under trunk you want to contribute. Then perform a right click on the selected item and hit "Checkout...".

In the next dialog shown below you have different options (dependent on the source code in the repository): either create a new project (if there is still no project information in the remote repository) which opens the standard Eclipse "New Project" dialog or you can checkout the project of the type specified by the source. As we describe the way of creating project in another tutorial we go on with the latter case. Therefor give the project a name and click "Next".

In the next dialog you can change the project's location. It is recommended to use the default workspace as the projects location.

After finishing the wizard you can switch back into "Java" perspective to see the working copy of the remotly shared project in the "Navigator" or "Package Explorer".
Building and deploying the project
In this article we talk about Maven2 based webprojects. Further more we assume that the source includes information on the Eclipse project configuration (ideally created with Maven2 using mvn eclipse:eclipse in the projects working directory), especially that Maven2 support is enabled via the M2 Eclipse Plugin from Codehaus. If the project's source does not contain any Eclipse project information the "New Project" wizard should have made it up for that. In case the project is not Maven2 enabled you can read on how to achieve this in the tutorial on setting up Java projects using Maven2 and Eclipse. In this tutorial you can also find information on how to perform basic Maven tasks.
Next I want to introduce you another nice feature of Maven! So, let's now stick into the issue of local deployment and testing of the webproject. As you know, Java based webprojects live in a servlet container at runtime on which they have to be deployed. You can't access any application or test any peace of code without the project beeing placed in this container. Thus you have to have a servlet container installed on your system and further more you should deploy the edited sources (or more precisely the compiled artifacts) to the container constantly. This can be a very stressy part in web development with Java. But luckily there is Maven!
Integrate Jetty deployment
The most simple way to ease deployment while development propably is using the Jetty servlet container in conjunction with their own Jetty Maven2 plugin which supplies hotdeployment and is very easy to configure. If you want to use other servlet containers you should use the Maven plugin Cargo as described in the tutorial on configuring Cargo deployment plugin.
To use Jetty deployment you simply have to use the following plugin configuration (within the <build><plugins> section of your project's pom.xml-file):
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
</configuration>
</plugin>
The only thing you have to do now is executing the command:
mvn jetty:run
Start Jetty from within Eclipse
Using Eclipse you do not have to type this command into a terminal window. Just create a m2 Configuration to run Maven via the m2 Eclipse plugin: open the "External Tools" dialog by executing "Run > External Tools > External Tools..." from the main menu. Double click on the "m2 build" label on the left side. Give the configuration a proper name, as base directory you should choose ${project_loc}, the goal you have to use is jetty:run. That's all! The following screenshot summarizes the settings:

By hitting "Run" in this dialog Jetty will be started, the webapp be packaged and deployed and finally your servlet container is ready for connections on the default port 8080. Try this link to the servlet container on your local machine.
Remember that ones you run this "External Tool" your project's target folder will be checked for changes constantly. You don't have to do anything for redeployment! Cool ah?
Propably the source code in the repository already contains a proper external tool configuration for the M2 plugin then you simply can use this instead of creating a second one. Sharing those external tool configuration can be reached by selecting the "Shared file:" option in the "External Tool" dialog, register "Common", section "Save as" and suppliing a location in the repository.
How to go on?
Now you're ready to develop webapplications in a team. After the installation procedure your normal tasks are the following:
- Update your working copy
when starting a coding session by selecting "Team > Update" in the context menu of the project's root folder. This will download the head revision of the project and prevents you from running into trouble with synchronization problems when commiting changes. - Make your changes
to the source code, add new files, folders etc. - Test your changes
by deploying the webproject to your local servlet container instance. Deployment will be done automatically after you've performed "Jetty run" (the Eclipse External Tool config) the first time. - Recheck your changes
which is a kind of warning: there is nothing more annoying for other developers if there are bugs in the repository code. - Commit your changes
along with a convenient message of the things you've changed.
Further more, if the project is enabled for continuous integration, go to the CI platform of your project (which URL normally is published on the project's homepage) and check if subsequent builds (that include your changes) run correctly.
Once you've done all those steps described above let me say "Congratulations", you're now a member and contributor of the open source community!
If you're interested in setting up an environment similar to the one used in this tutorial (including Maven project and SVN creation as well as continuous integration issues) please refer to the other eecoo tutorials on this topic.
