July 19, 2010: These instructions are out-of-date, confusing and need a full review. If you are using Eclipse with DSpace for development, please help us to simplify and clarify these instructions. Please, work with the new page at DSpace IDE - Eclipse, Git, Maven, and Tomcat. |
Obviously, to do this you will need to have Eclipse Installed: http://www.eclipse.org/
This HOW-TO has been written using Eclipse 3.4 (Ganymede), but it is also known to work in Eclipse 3.3 as well. The information here probably works with other versions of Eclipse, but no guarantees are made.
We need to install a variety of plugins to allow us to interact with DSpace and Tomcat in a fully integrated way. To install plugins into Eclipse you should use: Help -> Software Updates
On this page you will find a couple of pre-set install sites. For the plugins that we need we also need to add some new sites to this list (see next section), which is done by clicking on the "Available Software" tab, and clicking "Add Site.." on the right.
After you have installed all of these plugins, or in-between each one, you will need to restart the Eclipse workspace
Subversion (SVN) enables you to checkout the DSpace source code and keep up-to-date with the latest changes to the platform from DSpace Repository.
In Eclipse select "Help --> Install New Software...".
In the drop down list select "Helios - http://download.eclipse.org/release/helios."
From the list select "Collaboration --> Subversive SVN Team Provider"
Click the "Next >" button and follow the dialogs to install the plugins.
Restart Eclipse.
Eclipse ask you which Subversive Connector you want to use. Choose SVN Kit or JavaHL.
There are 2 popular SVN plugins for Eclipse. You only need to install one of them:
You should install the most recent version of your preferred client. The recommendation is SubVersive (as it is an Eclipse Incubation project), and the remainder of this tutorial assumes that this is the one you are using.
28th July 2007: This is an additional commentary on the current situation. As of version 1.1.3, Subversive uses the JavaHL bindings for the default Subversion client (this is the same as Subclipse). Whilst largely positive, this is not without it's side effects. Firstly, most of the unique functionality of Subversive will not work with JavaHL (it only works with JavaSVN, which is not only no longer the default, it's effectively deprecated). Secondly, the 'compare with' functionality does not work for folders, only individual files. For these reasons, it may be better for now to use Subclipse - which shares much of the same functionality, and the 'compare with' feature does work with folders (when using the JavaHL bindings). If you are thinking of switching to Subclipse from Subversive, then one thing you may find is that the labelling of new and changed files is not as clear as it was with Subversive. This can be rectified by going into preferences dialog, and under Team -> SVN -> Label Decorations, select the Text tab. Then set 'Label decoration for outgoing' to '>' and 'Label decoration for added' to '*' - this will effectively replicate Subversive's labelling.
Note: also that if you are using a plugin with the 'JavaHL' bindings, you will need to have the Subversion command line client installed and available on your path, and the JavaHL shared libraries installed and either ensure that the LD_LIBRARY_PATH environment variable is set to include the directory containing the JavaHL libraries, or that you include that path in a -Djava.library.path= definition in your eclipse.ini.
If you'd like to run Tomcat directly within Eclipse, and do some basic debugging, you may find it useful to install this Tomcat Plugin.
Install the most recent version of the plugin, which is available for download from:
http://www.eclipsetotale.com/tomcatPlugin.html
Unfortunately, there is no remote URL location for the sysdeo plugin. You will have to manually download the plugin and unzip it into the [eclipse]
/plugins
directory. Also, you will need to have Tomcat installed locally. Obtain the latest version of Tomcat from: http://jakarta.apache.org/tomcat
You only need to install Maven if you are using DSpace 1.5 or later.
Prerequisite: Before installing the Maven 2 Plugin for Eclipse, you must install Apache Maven from http://maven.apache.org/
Install the most recent version of the plugin using the below remote URL.
Remote URL: http://m2eclipse.sonatype.org/update/
The remote URL for the m2eclipse project has moved to: http://m2eclipse.sonatype.org/sites/m2e
These are tools for convenience in using Eclipse with web application projects such as DSpace. They are not required for having DSpace and Eclipse integrated, although they are useful
For Eclipse 3.2.2
This uses a pre-configured plugin site. Go to: Callisto Discovery Site -> Web & J2EE Development -> Web Standard Tools and select the checkbox on the left. This will alert you to required dependencies. Click "Select Required" on the right and this will resolve those dependencies.
For Eclipse 3.3
This uses a pre-configured plugin site. Go to: _Web Tools Platform (WTP) Updates -> Web Tools Platform (WTP) -> Web Standard Tools (WST) Project _ and select the checkbox on the left.
These are tools for convenience in using Eclipse with web application projects such as DSpace. They are not required for having DSpace and Eclipse integrated, although they are useful
For Eclipse 3.2.2
This also uses the pre-configured plugin site. Go to: Callisto Discovery Site -> Database Development and select the checkbox on the left (this will also select all the packages underneath that directory). Click "Select Required" to resolve the dependencies before installing
For Eclipse 3.3
This also uses the pre-configured plugin site. Go to "Europa Discovery Site -> Database Development '' and select the checkbox on the left selecting all the packages underneath that directory.
Obviously it's really up to you how you want your Eclipse to look, but this section details how to configure the tomcat plugin in general, and which views you will find useful to have included in your main Java Perspective.
tools.jar
file for the "Classpath (before generated classpath)". You should find this in the directory [installed jdk]/lib/tools.jar
Note: If you are using Mac OS X, the tools.jar
library does not exist on the platform. Instead using classes.jar
found at: /System/Library/Frameworks/JavaVM.framework/Versions/${JAVA_VERSION}/Classes/classes.jar
To add a new View to the current Perspective, use: Window -> Show View -> Other (in general). From here you can select the view to open from a list of available categories.
For some reason, Eclipse is configured by default to forbid direct use of some types which are defined in the JRE. There are a lot of new restrictions on version 1.6 of the JRE and this is one of them. You can find lots of queries and lots of advice about this on the Web, mostly to the effect that you can disable the error. It may be better, however, to take the rarer advice and rearrange the build path for an affected project:
(If you are working with DSpace 1.5 see the Working with DSpace 1.5 section after this)
NEEDS UPDATING – Not sure this actually works! [15 Apr 2008]
Now we have DSpace set up as a tomcat project, although it won't work yet until we've installed DSpace into the Eclipse Workspace ...
This section is principally the same as the standard DSpace installation, so assumes that you are familiar with that process, and doesn't dwell on potential difficulties.
The installation path you give should be:
dspace.dir = <workspace>/dspace/working-copy |
where <workspace> is the absolute path to your Eclipse workspace, and "working-copy" is the name of the directory into which we will install the DSpace application. Other configuration that you should ensure are set correctly are as follows (assuming installation on the local machine):
# DSpace base URL. Include port number etc., but NOT trailing slash dspace.url = http://localhost:8080/dspace-svn # DSpace host name - should match base URL. Do not include port number dspace.hostname = localhost # Name of the site dspace.name = DSpace 1.4.x in Eclipse |
The following resources will be needed to be set to SVN Ignore, to ensure that unwanted resources are not committed to the repository:
.cvsignore .tomcatproject build/ jsp/local jsp/WEB-INF/lib jsp/WEB-INF/web.xml work working-copy |
To set these to be ignored, right click on the resource and go: Team -> Add to svn:ignore then select "Resource(s) by name"
With the stages above complete you can now start tomcat and view the DSpace application in a web browser.
(Re)start the Tomcat web server through the Eclipse interface. This is done by clicking the right-most of the three tomcat buttons that are in the Eclipse toolbar courtesy of the SysDeo plugin. (In normal operation, you can restart the context without restarting tomcat, which can be done by right clicking on the project name and selecting Tomcat project -> Reload this context; furthermore, Eclipse will regularly auto-deploy the context while you are making changes). You can see the results of these actions reflected in the Console View if you have it open.
You should now find the DSpace deployed; try the following URL to see if it is working correctly:
http://localhost:8080/dspace-svn
Note that due to the limitations of the 1.4.x source structure, it is only possible to view one web application at a time from the same project when deployed within Eclipse. To work on the web interface and the OAI interface simultaneously you must use DSpace 1.5 and follow the instructions below. Otherwise, it is possible to modify this HOW-TO so that the OAI interface is deployed in Tomcat rather than the usual web interface.
DSpace 1.5 consists of several "modules", which better separate out the underlying DSpace API from the various user interfaces or web services available with DSpace. These modules are as follows (Note: some modules have sub-modules!):
dspace
- The root module, which builds all of DSpace and holds the DSpace configurationsdspace-api
- The DSpace API module, which contains all the primary business logic (Java code)dspace-jspui
- The JSP-based User Interface for DSpacedspace-xmlui
- The XML-based User Interface for DSpace (also known as Manakin)dspace-xmlui-api
- The primary API for the XML-UI for DSpace (including all Aspect Java code)dspace-xmlui-wing
- The Digital Repository Interface (DRI) API for XML-UIdspace-xmlui-webapp
- The XML-UI web application configurations (including all Aspect & Theme definitions)dspace-oai
- The OAI-PMH interface for DSpacedspace-lni
- The Lightweight Network Interface (LNI) for DSpacedspace-lni-core
- The primary API for LNIdspace-lni-client
- The client API for LNI (along with a simple sample client)dspace-lni-webapp
- The LNI web application configurationsdspace-sword
- The SWORD [interface for DSpacedspace-sword-api
- The SWORD APIdspace-sword-webapp
- The SWORD web applicationlanguage-packs
- The Internalization (I18N) language packs for DSpace (Currently JSP-UI only - the I18N for Manakin is in the dspace-xmlui-webapp
module)pom.xml
- The Maven module, which contains the primary Maven configurations to build DSpaceBecause DSpace 1.5 consists of many "modules" (see above), it lends itself to being worked with as several separate Eclipse projects! However, you do have some choice in how you want to work with DSpace 1.5 in Eclipse. Overall, there seems to be three main options (feel free to add more if you have other ideas):
Eclipse no longer supports the "Enable Nested Modules" option described below. See: https://issues.sonatype.org/browse/MNGECLIPSE-2291 |
This is the simplest approach and therefore is highly recommended for any new/novice developers. This approach allows you to checkout DSpace 1.5 as a single Eclipse Project. However, it only allows you to define a single user interface to debug tools using the Eclipse Tomcat plugin.
dspace-1_5_x
), and click "Finish". Eclipse will then checkout the DSpace 1.5 source code from SVN.pom.xml
configuration file and auto-configure your project as a "Java Project"!You now have a complete copy of DSpace 1.5 source code! Jump directly to the section on how to Build and Install DSpace.
This approach allows you to utilize the debugging tools available with the Eclipse Tomcat plugin, and treat your projects in a more "Maven-friendly" fashion. However, it will require you to create separate projects for each DSpace module.
Checkout each DSpace module as a separate Eclipse project, one-by-one, similar to the following:
dspace
- the primary module, which builds/configures DSpacedspace-api
- the DSpace API moduledspace-xmlui
module will be in an Eclipse project named "dspace-xmlui").pom.xml
configuration file under each of these projects, and auto-configure each project as a "Java Project"!Hints/Tips:
This approach attempts to combine the best of both of the above approaches. It allows you to utilize the debugging tools available with the Eclipse Tomcat plugin. It also allows you to potentially run two versions of DSpace 1.5.x side-by-side in the same Eclipse workspace (see Hints/Tips at end of this section). The disadvantage is that it is a little "messy", and requires that you checkout DSpace 1.5 to a location not in your normal Eclipse workspace.
svn co
https://dspace.svn.sourceforge.net/svnroot/dspace/branches/dspace-1_5_x
dspace-1_5_x-src
/tmp
). During the next step (when you will import the DSpace modules into Eclipse), Eclipse will not copy the code into your Eclipse workspace. Rather, it will just reference the location where you have checked out DSpace 1.5 via SVN...so, this location will (in a sense) become your DSpace 1.5 "workspace".m2eclipse
Maven plugin for Eclipse. If you attempt to re-import Maven projects which already exist in your Eclipse workspace, you will end up with a bunch of empty project folders.pom.xml
file in each DSpace module). It will display a list of all DSpace modules & sub-modules, and allow you to check which ones you wish to import. If you don't want to import all the modules at this time, you can always go back and repeat this same process to checkout additional modules.pom.xml
, since this is the module which builds DSpace.dspace-xmlui
or dspace-lni
(e.g. dspace-xmlui-api
is a submodule of dspace-xmlui
). This will decrease the number of separate DSpace projects in your Eclipse workspace.dspace-lni
, dspace-lni-core
, dspace-lni-client
, dspace-lni-webapp
). As mentioned, you can always repeat this process to import the DSpace LNI code if you need to, afterall. Notes:
Hints/Tips:
dspace-api
project to dspace-api-1.5alpha
(for the 1.5alpha version of this project).The Maven build tool will compile all the relevant parts of the DSpace application so that we can work on it in the correct environment.
Note: If you look closely, you'll notice that each project directory has its own pom.xml file. This file contains the instructions to the Maven build system which tell it what to assemble for that DSpace module. The pom.xml file in the dspace
project directory contain primary Maven instructions, and references all of the other pom.xml files.
To ease building/cleaning your DSpace projects, it's highly recommended to create some quick "tasks" within Eclipse's "External Tools Dialog". To get to the External Tools Dialog, look in the Eclipse toolbar for the Green "play" (>) button with a Red toolbox under it. Click on it, and select "Open External Tools Dialog".
dspace
sub-module (or separate project).dspace
sub-module (or separate project).dspace-jspui
sub-module (or separate project).dspace-xmlui
sub-module (or separate project).dspace-oai
) or LNI (dspace-lni
) similar to those for the XMLUI and JSPUI.After creating these tasks, you may want to add them to your "Favorites", so that they appear in your External Tools Dialog dropdown. Click back on the External Tools Dialog button, and choose "Add to Favorites". Then, add all of your tasks to your favorites!
Just run your DSpace Assemble task, as detailed in the Defining Maven Tasks in Eclipse section above.
If you are looking at the Console view in Eclipse, you will know the build has been successful when you see it terminate with a message similar to the following:
[INFO] ---------------------------------------------------------------------------- [INFO] BUILD SUCCESSFUL org.dspace:dspace:pom:1.5-SNAPSHOT ( task-segment: [package] ) [INFO] ---------------------------------------------------------------------------- [INFO] Total time: 32 second [INFO] Finished at: Tue Nov 27 14:17:56 CST 2007 [INFO] Memory 8M/63M [INFO] ---------------------------------------------------------------------------- |
You will need to select your DSpace 1.5 Eclipse project(s), Right Click, and select "Refresh" to see the changes that this makes to each of the components. You will notice that it has inserted a new directory in every module called target
which contains the result of the build process.
Under your dspace
project or sub-module, you should now have a /target/dspace-<version>.dir/
, which is the pre-installation package of DSpace 1.5. It is from here that we must initialize our local copy of the application for development.
Before we do any build work, we must prepare the DSpace configuration.
C:\dspace
or /dspace
)config
folder here, and copy the <workspace>/dspace/target/dspace-<version>.dir/config/dspace.cfg
to this <dspace>/config
location.dspace.cfg
file to contain the correct configuration for your intended DSpace installation.The most critical things to get right are the installation path and the database path. This documentation does not cover setting up the DSpace database, but you should do this before going any further. Please refer to the DSpace System Documentation for additional instructions.
The installation path you give should be:
dspace.dir = <dspace> |
where <dspace>
is the absolute path of the folder where you want DSpace to be installed. Other configuration that you should ensure are set correctly are as follows (assuming installation on the local machine):
# DSpace base URL. Include port number etc., but NOT trailing slash dspace.url = http://localhost:8080/dspace-jspui # DSpace host name - should match base URL. Do not include port number dspace.hostname = localhost # Name of the site dspace.name = DSpace 1.5 |
Now, we want to create a fresh installation of DSpace. This will create our database properly, and setup the <dspace> installation location. (You only need to do a "fresh install" once! So, you can skip this, if you've already done it)
dspace
project/sub-module, locate /target/dspace-<version>.dir/build.xml
. This is the Ant build file for DSpace.build.xml
file and select Run As -> Ant Build ...-Dconfig=<dspace>/config/dspace.cfg
, where <dspace> is the full path of the folder where you are installing DSpace.If you are looking at the Console view in Eclipse, you will see it installing DSpace, and creating and preparing the database.
You only need to follow these steps if you want to integrate your DSpace projects with the Eclipse Tomcat Plugin.
In order to ensure the Tomcat Plugin can run off of the web applications within the various /target/
directories, we need to tell all of our Maven build tasks where our dspace.cfg
configuration file is.
Go back into each of the Maven build tasks you defined in the Defining Maven Tasks in Eclipse section above, and add the following parameter:
dspace.config = <dspace>/config/dspace.cfg |
where <dspace> is the full path of where you installed DSpace.
Note: You do not need to make this change for the DSpace Clean task, as it doesn't need to know where this configuration file resides.
Finally, reassemble all of DSpace by rerunning your DSpace Assemble task.
If you would like the ability to perform live debugging through the Eclipse Tomcat Plugin, you will need to setup the appropriate DSpace web interface projects as Tomcat Projects.
The project properties that you would need to modify are available by Right Clicking on the project name and
selecting Properties -> Tomcat.
dspace-1_5
(this context path can be anything and is what you want Tomcat to use in the URL)dspace-jspui
, set the web application root to be: /dspace/target/dspace-<version>-build.dir/webapps/jspui
dspace-oai
, set the web application root to be: /dspace/target/dspace-<version>-build.dir/webapps/oai
dspace-xmlui
, set the web application root to be: /dspace/target/dspace-<version>-build.dir/webapps/xmlui
dspace-lni
, set the web application root to be: /dspace/target/dspace-<version>-build.dir/webapps/lni
/target/dspace-jspui-<version>
/target/dspace-oai-<version>
/dspace-xmlui-webapp/target/dspace-xmlui-webapp-<version>
/dspace-lni-webapp/target/dspace-lni-webapp-<version>
With the stages above complete you can now start tomcat and view the DSpace applications in a web browser.
(Re)start the Tomcat web server through the Eclipse interface. This is done by clicking the right-most of the three tomcat buttons that are in the Eclipse toolbar courtesy of the SysDeo plugin. (In normal operation, you can restart the context without restarting tomcat, which can be done by right clicking on the project name and selecting Tomcat project -> Reload this context; furthermore, Eclipse will regularly auto-deploy the context while you are making changes). You can see the results of these actions reflected in the Console View if you have it open.
You should now find the web interface deployed; try one of the following URLs to see if they are working:
http://localhost:8080/dspace-jspui (JSP-UI)
http://localhost:8080/dspace-oai/request?verb=Identify (OAI-PMH)
http://localhost:8080/dspace-xmlui (XML-UI)
There are lots of things you can do with the database connection, including issuing queries, so it's worth playing around with.
Well, aside from the obvious benefits of having everything compiled in the background while you are working, and having everything, including database browsing and querying integrated into your development environment, consider the following exercises:
private void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException |
and find the line of code which reads:
// Are we resuming a previous request that was interrupted for // authentication? request = Authenticate.getRealRequest(request); |
around line 136.
public static BrowseInfo getItemsByTitle(BrowseScope scope) throws SQLException { scope.setBrowseType(ITEMS_BY_TITLE_BROWSE); scope.setAscending(true); scope.setSortByTitle(null); return doBrowse(scope); } |
around line 165 of Browse.java
This example is particularly cool because the code with the breakpoint in it is in a separate project to the JSPUI, which is the application you actually loaded through the UI. By including the classes produced by the dspace-api project into the library of the dspace-jspui project, it means that we can debug across both projects simultaneously, as well as the same piece of API code accessed from multiple interfaces (e.g. OAI).
There are plenty of opportunities for this sort of integration to be useful, and I would encourage people to add their tips and tricks to this page.