Sunday, November 21, 2010

Configuring UCM application in Eclipse IDE

I tried to set up a development environment to create custom Java components for UCM application using Eclipse IDE. There is a step by step procedure available in Bex's book and that should suffice to set up development environment for most people. But somehow I was unable to get it set up and working.

After a lot of trial and error method, I got the Content Server to start from within the IDE. I thought of sharing my experience with those who are new to development of custom Java components.

The following step by step procedure is for UCM 10gR3 and Eclipse version 3.4.2.

First let us create a simple component 'MyFirstComponent' using Component Wizard. Using this component let us change the filename that is displayed to the title entered during check-in.
We can achieve this by writing a filter using validateStandard.

Lets set up the component in Eclipse.

Follow the below steps.
1) Open Eclipse.
2) Windows -> Preferences -> Java Compiler and set it to Java 1.5.
3) File -> New -> Project -> Java Project.
4) Name the project MyFirstComponent and click Next.
5) In the Source tab, click the Browse button which is present at the bottom of the page besides the Default Output Folder text box.
6) In the Folder Selection dialog box, select the project name and click Create New Folder button.
7) In the New Folder dialog box, enter the folder name as classes and click the Advanced>> button.
8) Select the Link to folder in the file system check box. Click browse and browse to the directory ucm/custom/MyFirstComponent/classes. If classes folder is not there, it must be created and then linked.
9) Click OK and set the Default Output Folder to MyFirstComponent/classes.
10) In the Libraries tab, add all the jars needed to be in the class path. Some of the mandatory jars are given below.
ucm/shared/classes/server.zip
ucm/shared/custom/Folders_g/classes.jar
It depends on what all is being used in the components.
11) Click Finish.

Now in the src folder of the project, create a package named myfirstcomponent

Then create the below class file in that package.

package myfirstcomponent;
import intradoc.common.ExecutionContext;
import intradoc.common.ServiceException;
import intradoc.data.DataBinder;
import intradoc.data.DataException;
import intradoc.data.Workspace;
import intradoc.shared.FilterImplementor;

public class MyFilter implements FilterImplementor
{
public int doFilter(Workspace ws, DataBinder binder,
ExecutionContext cxt) throws DataException, ServiceException
{

String title = binder.getLocal("dDocTitle");
String fileName = binder.getLocal("primaryFile");

String newFileName = title + fileName.substring(fileName.lastIndexOf("."));
binder.putLocal("primaryFile",newFileName);

return FilterImplementor.CONTINUE;
}
}

Now build the project, the class file for the above java file, should be created in the path
ucm/custom/MyFirstComponent/classes.

The class file also should be displayed in the classes folder of the proj in Eclipse IDE.

Next configure the above created filter in the component definition file. Open the MyFirstComponent.hda file located in the below location.
ucm/custom/MyFirstComponent/MyFirstComponent.hda

Configure the filters as below.
@ResultSet Filters
4
type
location
parameter
loadOrder
validateStandard
myfirstcomponent.MyFilter
null
1
@end

Select the Project in the Eclipse and click Run Configurations from the Run menu.

Run Configurations dialog box would have opened. Select Java Application from the left menu and click New icon from top.

Give it the name MyServer.
In the Main tab, for the project browse and select our project MyFirstComponent. Then for the Main class enter IdcServer.

In the Arguments tab, in the Working Directory section, select other and enter the below path.
D:\oracle\ucm\server\bin (For you it might be different). You can click FileSystem button and browse and select the directory.

In the Environment tab, click New and enter the following name-value pair
Name : PATH
Value : D:\oracle\ucm\server\shared\os\win32\lib

You can add more libraries, by separating with a semicolon. It purely depends on your project.
Click Apply and Close button.

Now we are all set to start the content server from the IDE. Click Run from the Run menu.

The content server should start in the Eclipse. Now open a browser and type the url for the application. In my case it was http://localhost/idc. Then check-in a file. The filename after check-in should be display the title that was entered during check-in.

To run the in Debug mode, just click Debug from Run menu.

Happy debugging using Eclipse for UCM applications.

Leave your comments if you have any suggestions,corrections or queries. Have a good day..

5 comments:

Pradeep said...

This one is really great selvam...

greddin said...

This is a great article! Very simple to follow. I just had one question though. I followed your instructions for build path but my Eclipse is outputting the class file into an additional package folder like this: /oracle/ucm/server/custom/MyFirstCompoent/classes/myfirstcomponent/MyFilter.class. Is this a global Eclipse setting I need to change? Thanks!

Selvam said...

You should only create a link to the component classes folder.
No global setting is required for this.

Cheers.

lorddisk said...

great but i wanna to configure UCM11 with eclipse
as files paths are changed
thanks in advance

Priya said...

Great post! The steps were easy to follow & was able to set up my first component!