|
By Jim Faut and Marina Sum, October 18, 2005
|
|
|
Painless SOA You can use Sun Java Studio Enterprise to build effective Web services. Sun Java Studio Enterprise frees you to focus on business logic because it handles the low-level details of Web services, such as SOAP and WSDL, with time-saving wizards and test clients.
|
Today, many Java developers build applications in integrated development environments (IDEs). Enterprise portal projects, in particular, demand a complex environment of developers, servers, and tools. However, reference material that explains how to configure IDEs specifically for developing and deploying portals is sparse.
In answer to that need, this article shows you how to configure an IDE with Sun Java Studio Enterprise 8 (henceforth, Java Studio Enterprise 8) and Apache Ant for development with Sun Java System Portal Server (henceforth, Portal Server). Subsequently, you can run Ant tasks to build and deploy a portal installation on a single remote server or multiple servers. Figure 1 is a high-level overview.
Figure 1: Developing, Staging, and Producing Portals With Java Studio Enterprise 8 |
Note that integrated with Java Studio Enterprise 8 is Portlet Builder, a facility for developing portlets locally within the IDE. This article focuses on an approach for advanced enterprise environments that require scripted deployment capabilitieseither with or without an IDE.
Contents
Software Requirements
Before configuration, ensure that you have the following software from Sun:
Configurations for Java Studio Enterprise 8 Projects
To create a project directory in Java Studio Enterprise 8, follow the procedure in this section. Figure 2 shows a typical project directory.
Figure 2: Typical Project Directory in Java Studio Enterprise 8 |
Adding Display Profile Documents
First, download profile documents from Sun Java System Access Manager (henceforth, Access Manager) and store them as XML files in the project directory. Afterwards, you can distribute these documents to other portal servers, for example, for staging and production.
Here are the steps:
- Create a folder in the project called
DisplayProfile.
- Download each of the display profile documents for the organizations and roles that you have defined.
- Append the document names with a
.xml extension so that the IDE recognizes them as XML documents.
- Optional. Create a directory structure under
DisplayProfile that mimics the organizational structure in Access Manager.
- Download the Global Display Profile.
Adding JavaServer Pages Templates
Next, do the following to create JavaServer Pages (JSP) templates:
- Create a folder in the project called
Templates.
- Under
/etc/opt/SUNWps/desktop on Portal Server, tar and gzip the anonymous and sampleportal directories.
- Download the archive and extract the contents into the
Templates folder.
Adding the Portal SDK
Now create a directory called build-lib for the external Java archive (JAR) files that are required to compile Java classes. Afterwards, perform two more tasks:
- Download the
desktopsdk.jar file and place it under build-lib.
- Add
desktopsdk.jar to your classpath.
The desktopsdk.jar file is in the /opt/SUNWps/sdk/desktop directory of your portal installation.
Adding the JSR 168 Portlet API
The portlet.jar file is a prerequisite for compiling Java Specification Request (JSR) JSR 168 portlets. Download it from the JSR 168 site.
Alternatively, copy the file from the portal installation in the Portal_Server_home/SUNWps/lib directory and then place the file in the build-lib directory of your project.
Adding the Java Servlet API
Afterwards, add the Java 2 Platform, Enterprise Edition (J2EE platform) API JAR file to the build-lib directory and to your classpath. This file is part of the J2EE 1.4 Reference Implementation available at the latter's download site
Note the following:
- If you are using Sun Java System Web Server, this JAR file is called
webserv-ext.jar under Web_Server_home/bin/https/jar/.
- If you are using Sun Java System Application Server, this JAR file is called
j2ee.jar under App_Server_home/lib/.
Customizing Java Code
Now create a directory called src for your new, custom Java code and add src to the list of source directories for the project. Your Java package structure will reside in this directory.
Downloading JAR File for Java Secure Shell
The Secure Shell (SSH) commands that are executed by the Ant script require the JAR file for the Java Secure Shell (JSCH), called jsch-0.1.21.jar. Download that file from JCraft and add it to the Ant classpath. See Figure 3.
Figure 3: Addition of the JSCH JAR File to the Ant Classpath |
Afterwards, when you deploy the code, SSH commands execute scripts and commands on the remote portal server.
Configurations of Remote Portal Server
This section shows you how to modify a portal installation, after which deploying code will be a breeze. Repeat these steps on each of your Portal Server installations.
Creating Build Users
First, on Portal Server, create a build user, who then belongs to a group with write permission for the Portal Server file system. Do the following:
- Become root.
- Type:
groupadd portal
- Type (all on one line):
useradd -d /export/home/pbuild -s /bin/bash -m -k /etc/skel -g portal pbuild
- Type:
passwd pbuild
Follow the prompts to create a password for this user.
- Edit the
.profile file as follows:
| a. |
Add umask 002 to the end so that the user can create or edit the files and directories on the portal. |
| b. |
Change the user's path to include the location of the Sudo application, typically at /opt/sfw/bin. Your Sudo installation may be in a different location, however. |
Changing Directory Permissions
Now change permissions on several portal files and directories to grant write permission to the build user:
- Type
chmod 755 /etc/opt/SUNWps to grant write access to the portal directory.
- Type
chown -R pbuild:portal /etc/opt/SUNWps/* to change the group ownership of the portal template files.
- Type
chmod -R g+r /etc/opt/SUNWps/* to grant group read permission for the portal template files.
- Type
chmod -R g+w /etc/opt/SUNWps/* to grant group write permission for the portal template files.
- Type
chmod -R g+s /etc/opt/SUNWps/* to set the setuid bit for the directories.
New directories are then owned by the portal group.
Configuring Sudo
With the Sudo application, you can function as roota prerequisite for executing commands in the Portal_Server_home/SUNWps/bin and App_Server_home/SUNWappserver/appserver/bin directories. By configuring Sudo, you enable users in the portal group to run certain commands.
You can install Sudo from the Companion CD for the Solaris 10 Operating System. Afterwards, run the visudo command to edit the sudoers file and add the following entries to the Cmnd Alias Specification section.
Cmnd_Alias PORTAL_CMDS=/opt/SUNWps/bin/pdeploy, /opt/SUNWps/bin/dpadmin
Cmnd_Alias CONTAINER_CMDS=/opt/SUNWappserver/appserver/bin/asadmin start-
domain*, /opt/SUNWappserver/appserver/bin/asadmin stop-domain*
%portal ALL=NOPASSWD: PORTAL_CMDS, CONTAINER_CMDS
|
Subsequently, users in the portal group can modify the display profile, deploy or undeploy portlets, and start or stop the server without root privileges. For details on Sudo, see the man pages for sudo and sudoers.
Updating the build.properties File
The build.properties file contains the information required by Ant to deploy the portal to Portal Server, that is, sample values that you must update according to your specific configuration. Update them as follows.
dev.sudo.cmd=/opt/sfw/bin/sudo
dev.host=host.company.com
dev.org_dn=dc=company,dc=com
dev.portal_install_dir=/opt
dev.pdeploy.cmd=${dev.portal_install_dir}/SUNWps/bin/pdeploy
dev.dpadmin.cmd=${dev.portal_install_dir}/SUNWps/bin/dpadmin
dev.amadmin.cmd=${dev.portal_install_dir}/SUNWam/bin/amadmin
dev.amadmin_user=uid=amadmin,ou=people,${dev.org_dn}
dev.amadmin_user.pwd=password
dev.portal_container_user.pwd=password
dev.deploy.user=pbuild
dev.deploy.pwd=pbuild
|
By way of explanation
dev.sudo.cmd The location of the Sudo application
dev.host The host of the portal server for SSH commands
dev.org_dn The root suffix of your directory server installation
dev.portal_install_dir The base directory for your portal installation
dev.admin_user.pwd The password for the amadmin user
dev.portal_container_user.pwd The password for the administrator for the portal Web container
dev.deploy.pwd The new build user's password
These properties are for the dev environment. For additional environments, simply create more property files with different prefixes. For instance, for the staging, UIT, and production environments, create three copies of this property file and name them staging.properties, uit.properties, and production.properties.
Updating the build.xml File
Finally, for additional environments, edit the build.xml file. First, create copies of these three targets for each environment:
deploy_dev
build_dev
replace_dev
Update each of the targets to include the new properties you just added to the build.properties file.
Sample Projects
Download the sample code, which contains the following:
- Source code for the sample portlet
- Source code for the sample provider
- Sample Ant script and properties file for building and deploying the project
- Sample server-side scripts for deploying portlets and providers and for displaying profile documents
Here are the details.
 |
IDEConfigProvider.xml
|
DisplayProfile/providers
|
Display profile for the sample provider |
sunlogo.gif
|
portlets
|
Image for the sample portlet |
content.jsp
|
portlets/idesample
|
Content for the sample portlet |
help.jsp
|
portlets/idesample
|
Help for the sample portlet |
JSPPortlet.java
|
portlets/src/com/sun/portal/ portlet/samples/jspportlet
|
Source code for the JSP portlet |
portlet.xml
|
portlets/WEB-INF
|
Descriptor for deploying the sample portlet |
sun-portlet.xml
|
portlets/WEB-INF
|
Sun-specific descriptor for portlet deployment |
sun-web.xml
|
portlets/WEB-INF
|
Sun-specific descriptor for deployment |
web.xml
|
portlets/WEB-INF
|
Deployment descriptor |
build.properties
|
scripts/build
|
Ant properties file |
build.xml
|
scripts/build
|
Ant build script |
batch_load.sh
|
scripts/deploy/portal
|
Script for deploying display profile documents |
batch_load.txt
|
scripts/deploy/portal
|
Instructions for deploying display profile documents |
deploy.sh
|
scripts/deploy/portal
|
Server-side deployment script |
deploy_portlet.sh
|
scripts/deploy/portal
|
Portlet deployment script |
loadglobaldp.sh
|
scripts/deploy/portal
|
Script for updating the global display profile |
loadroledp.sh
|
scripts/deploy/portal
|
Script for updating display profile documents for roles |
loaduserdp.sh
|
scripts/deploy/portal
|
Script for updating the user display profile |
removeuserdp.sh
|
scripts/deploy/portal
|
Script for deleting a user display profile |
undeploy_portlet.sh
|
scripts/deploy/portal
|
Script for undeploying a portlet |
IDEConfigProvider.java
|
src/com/sun/portal/providers/ideconfig
|
Source code for the sample provider |
Creating Java Studio Enterprise 8 Projects
This section walks you through the steps for creating a Java Studio Enterprise 8 project with the contents of the ZIP file.
- Unzip the file into a working directory.
- Create a new project in Java Studio Enterprise 8 as a Java project with an existing Ant Script. See Figure 4.
- Specify the locations of the project folder and Ant script and then name the project. See Figure 5.
- Specify the location of the source code and add the
/src and /portlets/src directories. See Figure 6.
Figure 6: Location for Source Code and Additional Directories (Click to enlarge.) |
- Add the JAR files that are required to build the project. See Figure 7.
- Add the JSCH JAR file from JCraft to the Ant build path. See Figure 8.
Figure 8: Addition of the JSCH JAR File |
- Download the Global Display Profile and Organization Display Profiles from Portal Server and place them in the
DisplayProfile/global and DisplayProfile/TopOrg directories, respectively. See Figure 9.
Figure 9: Placement of Global Display Profile and Organization Display Profiles |
- Create an archive of the template files on the two Portal Server directories,
/etc/opt/SUNWps/desktop/anonymous and /etc/opt/SUNWps/desktop/sampleportal, by typing these commands:
# cd /etc/opt/SUNWps/desktop
# tar cvf templates.tar anonymous sampleportal
# gzip templates.tar
You'll see a new file called templates.tar.gz. Download it and extract the contents to the Templates directory of your project. See Figure 10.
Figure 10: Placement of Extracted Contents of templates.tar.gz |
- Optional. To compile the files, first do the following:
| a. |
Open the IDESampleProvider.java file in the editing window. Press F9 to compile.
Java Studio Enterprise 8 prompts you to confirm the creation of an Ant build target for compilation. See Figure 11.
Figure 11: Dialog Box With Prompt for Creating an Ant Build Target |
|
| b. |
Click Generate.
Java Studio Enterprise 8 then creates an Ant script and displays it in the editor. |
| c. |
Edit the value for the property build.classes.dir to read bin/Templates/classes. See Figure 12.
Figure 12: Editing of the Ant Script |
You can now compile your files. The generated class files reside under the bin/Templates/classes directory. |
Understanding the Build Process
The build process proceeds with the execution of the deploy_dev Ant target, as shown below.
 |
clean
|
Delete files in the target directory. |
prepare
|
Create directories for distribution files. |
jar
|
1. compile
| |
a. |
clean |
| b. |
Compile Java sources for providers and portlets. |
| c. |
Call the copyFiles Ant target.
| i. |
Copy files from the project directory to the distribution directory. |
| ii. |
Correct the CRLF characters in the UNIX deployment scripts. |
| iii. |
Add execute permissions for deployment scripts. |
|
2. Create a JAR file with the required files for PAPI providers and other related files.
|
replace_dev
|
Perform string substitutions on certain files. |
war_portlet
|
Create the portlet's Web archive (WAR) file. |
zip_templates
|
Create the ZIP file that is deployed to Portal Server. |
scp (1)
|
Copy the template.zip file to Portal Server.
Copy the portlets.war file to Portal Server. |
sshexec (1)
|
Unzip the templates.zip file.
Execute the deploy.sh script on Portal Server to deploy the portlets.war file. |
(1) This command is called twice.
Deploying to Multiple Environments
Often, a project team must deploy code to development, staging, and production systems. You can extend the Ant script to support multiple deployment environments. Follow these steps:
- Create new deployment targets, such as
deploy_test, deploy_prod, and so forth.
- Update the
build.properties file and add property sections for each of the new deployment environments.
The new property file names have a corresponding prefix of staging or prod, followed by a dot.
- Create a corresponding
replace_test or replace_prod target to ensure that the correct host names and passwords are in use.
Sample Providers
Here are two sample portlet providers.
IDEConfigProvider
IDEConfigProvider is a Provider Application Programming Interface (PAPI) provider that simply displays a hello message. See Figure 13.
Figure 13: IDEConfigProvider |
IDEConfigPortlet
IDEConfigPortlet, a JSR 168 portlet that demonstrates how the Ant script packages and deploys portlet code, extends the JSPPortlet sample shipped with Portal Server. The code resides in the portlets directory. See Figure 14 for the images that depict the content.jsp and help.jsp files.


Figure 14: IDEConfigPortlet |
Summary
In this article, you've learned how to configure the Java Studio Enterprise 8 IDE so that you can build and deploy portal providers and portlets and display profiles there. The procedures are similar for the IDE's other versions. In addition, you can adapt the procedures to other IDEs of your choice. In employing Ant for the builds, you can deploy the code to multiple environments with any IDE-platform combination.
Bear in mind that customizing the Ant script for deploying to other environments is a snap. Simply create additional Ant targets for each of the environments and revise the build.properties file accordingly.
References
|