Hello World - WebSphere Portal V5 The simplest portal: Part 1, creation, and deployment

xiaoxiao2021-03-06  70

This article will take you to the steps of creation and deploying a simple portlet in WebSphere Portal Version 5.

Introduction, some people often ask me this question: "If you start from the beginning, what is the simplest portlet created by WebSphere Portal Version 5?". The fixed answer is "Hello World". This article will take a long time to answer this question in detail. I am going to take you to learn how to create the easiest Protlet for WebSphere Portal V5. You will start from some Java code, then compile it, then package it. Next, you will create the deployment descriptor required for the application server and portal information about the information about portlets. Finally, we pack them together and deploy new portlets to the portal.

Creating a directory structure first creates a directory structure and you will create a portlet in this directory structure. Below is the directory structure I will use in this simple portlet:

HelloWorld / COM / IBM / Portlets / Sample - Position of the source code HelloWorld / Web-INF - Deploy the location of the descriptor HelloWorld / WEB-INF / LIB - JAR file storage

Creating a Java file Sample directory is where you will store the Java source code. Create a file called HelloWorld.java in the sample directory, then open the file with your favorite text editor. Here is the class you need to enter (or copy, paste) to the HelloWorld.java file:

Package com.ibm.portlets.sample;

// portlet APIT

Import org.apache.jetspeed.portlet. *;

// java stuff

Import java.io. *;

Public class helloworld extends portletadapter {

Public void

Service (PortletRequest)

REQUEST, PortletResponse

Response)

Throws portletException,

IOEXCEPTION {

PrintWriter Writer =

Response.getwriter ();

Writer.println ("Hello, World");

}

}

Compiling Code Once you have created a source file, you can compile the Java code. In a batch file, you can use the following scripts to compile portlets. You first define some environment variables (for example, the location of the Java home directory). The JDK with WebSphere Application Server is compiled for this is usually a good idea, because this is the environment you want to run. You have to set the PATH to access the Java compiler. In addition, it is also necessary to set the variable libpath to point to the directory where the WebSphere JAR file is located.

Next, you build a variable called CP for our compile class path. The CP variable can be constructed on one line, but to illustrate the different JAR files required, we disassemble the branch display. Then, you call the Java compiler to compile the code. This assumes that you are located in the HelloWorld directory. Please adjust the directory path to the path that is fit.

Set java_home = c: / WebSphere / AppserVer / Java

SET PATH =% java_home% / bin

SET LIBPATH = C: / WebSphere / AppServer / LIB

SET CP =.

SET CP =% CP%;% libpath% / j2ee.jar

SET CP =% CP%;% libpath% / Dynacache.jar

SET CP =% CP%; c: /websphere/portalser/shared/app/portlet-api.jar

Javac-ClassPath% CP% COM / IBM / Portlets / Sample / HelloWorld.java

If you can't compile some reason, you must have a correct error before going down. Some common mistakes are:

Enter an error - class name, path, and variable name Enter the error file name - the file name must match the class name. In our example, the file name is HelloWorld.java, and the class name is HelloWorld. If you have changed a name, another name is also changed. Editor Error - Determines the editor to store files as text. Like a editor like writing, you will not store the file to text by default.

Creating a JAR file After completing the compilation of the Java source file, you need to create a JAR file in a web-inf / lib directory. Have a hypothesis that you are located in the HelloWorld directory. If you create a batch file in the Compile Code section, you can include part of the file as part of the file. This depends on the PATH set to point to the JAR program.

Set java_home = c: / WebSphere / AppserVer / Java

SET PATH =% java_home% / bin

Jar -cv0f ./web-inf/lib/helloworld.jar COM / IBM / Portlets / Sample / *. Class

Create a deployment descriptor now, you need to create two XML files:

HelloWorld / Web-INF / Web.xml - Web Deployment Descriptor. HelloWorld / Web-INF / portlet.xml - portlet deployment descriptor.

Web.xml - Web Deployment Descriptor Web Deployment Descriptor is required for WebSphere Portal. Now the portlet extends servlet, so you need to use the web deployment descriptor to declare the Servlet (portlet) class.

"1.0" encoding =

"UTF-8"?>

Public "- // Sun microsystems, Inc.//dtd Web Application 2.3 // en"

"http://java.sun.com/dtd/web-app_2_3.dtd">

HelloWorldportlet <

/ Display-name>

HelloWorld <

/ servlet-name>

com.ibm.portlets.sample.helloworld <

/ servlet-clas>

"Servletmapping_1">

HelloWorld <

/ servlet-name>

/ helloworld / * <

/ url-pattern>

portlet.xml - Portlet Deployment Descriptor Portlet Deployment Descriptor Defines the portal. Each portlet is mapped to a servlet defined in the web deployment descriptor through the HREF property of the portlet element. These references are represented by bold. Portlets must define a unique ID, each of which can reference the ID. Each specific portlet uses the specific ID of the HREF attribute of the Concrete-Portlet element to reference the portlet. Represents these references in blue.

"1.0" encoding =

"UTF-8"?>

PUBLIC "- // ibm // DTD portlet application 1.1 // en" "portlet_1.1.dtd">

"com.ibm.ports.sample.helloWorld.1" major-version = "1"

Minor-version = "0">

HelloWorld0Portlet <

/ portlet-app-name>

Minor-verion = "0">

HelloWorld <

/ portlet-name>

0 <

/ expresss>

NO <

/ shared>

"html">

"com.ibm.ports.sample.helloWorld.1.2">

Concrete HelloWorld <

/ portlet-app-name>

Author <

/ param-name>

tcat@us.ibm.com <

/ param-value>

HelloWorld <

/ portlet-name>

EN <

/ Default-local>

"en">

Hello World </ Title></p> <p><title-short> </ title-short></p> <p><Description> </ description></p> <p><Keywords> </ keywords></p> <p></ logage></p> <p></ concrete-portlet></p> <p></ concrete-portlet-app></p> <p></ portlet-app-def></p> <p>Many places will be wrong when you create these XML files. These errors are only found when you try to deploy portlets to the portal. There are some places that need special attention:</p> <p>Check each XML element to make sure they have an off element. Check if the name is incorrect, for this example, check if the name of your giving class is HelloWorld. Make sure the ID and HREF match. Make sure the editor really saves files into text.</p> <p>Creating a WAR file Finally, we can create a distributed WAR file. We will use standard JAR commands to build a WAR file. Run the following command in the HelloWorld directory:</p> <p>Set java_home = c: / WebSphere / AppserVer / Java</p> <p>SET PATH =% java_home% / bin</p> <p>Jar -cf HelloWorld.war Web-INF</p> <p>Deploy WAR file</p> <p>Log in to the portal in the identity (wpsadmin) of the portal administrator. Select the Administration link in the upper right corner of the default theme. Figure 1. The administrator links to the left to select the portlets page and select Install portlet. Figure 2. Install the portlet management page Click. Find the location of the WAR file, selected, and then click. Figure 3. File Selection Dialog Click. This may take some time, please wait patiently to complete it. Verify that the portlet is HelloWorld. Click. Wait again until the installation is complete. Figure 4. Portlet Installation Verification Screen Finally, you will see this confirmation message:.</p> <p>If you encounter a class error message during the deployment process, this usually means that you have an error in an XML file. Carefully analyze the installation page presentation to your error message, you usually find the reason for the error. This information will also be recorded in the latest log files:% wps_home% / log / wps_yyyy.mm.dd-hh.mm.ss.log</p> <p>Creating a deployment descriptor lists common errors for XML files. You should also check the following:</p> <p>The XML declaration must be on the first line of the file (no space). In the case of correct case, the XML file has the correct name.</p> <p>Add portlet to a page</p> <p>Select the Portal User Interface page on the left. Click on the Manage Pages Portlet. Figure 5. Management page portlet then select My Portal page. Click. Type a title for the new page. Click. I saw later. Click the Edit page icon on the side of the new page. Click. Search Hello, click. Check the Hello World Portlet and click. Figure 6. Find portlets Click to complete the page layout design. Figure 7. Editing Layout Design Click the My Portal link in the upper right corner, then select the page you created. Figure 8. Portal showing the portlet we created</p> <p>End language now you have created a new portlet, you should be happy! You now know how to create a simple portlet from your head. First write, compile and package Java code. Then create a deployment descriptor and package the portlet to distribute and deploy. Finally, deploy portlets into your portal. From now on, writing any portlet is possible for you. I wish you good luck and have fun!</p> <p>Back to top</p> <p>Reference</p> <p>WebSphere Portal Product Documentation WebSphere Portal Zone</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-92468.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="92468" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.043</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = '_2FaqMvbiKY0PbnUudwfnDVp_2FmSQahxvaHWdug8CUJ_2BhQ_2BaPt8xiAfbk4bslABXQF2BK5FEh9yLP6KOloeZKg0mw_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>