You are on page 1of 24

External Library Deployment and

Usage in SAP NetWeaver
Developer Studio (NWDS)

Applies to:
SAP NetWeaver, SAP NetWeaver Developer Studio 7.0.16, SAP Java, External Libraries For more
information, visit the Java homepage.

Summary
This article will guide you through step by step process of using an external library in existing web
application. An external library Development Component will be first created and then deployed to
application server.

Author: Saurabh Agarwal
Company: Steria, India
th
Created on: 27 February 2010

Author Bio

Saurabh Agarwal is working as a Consulting Engineer with Steria India Ltd. He has been
involved in Java based portal development (Netweaver Developer Studio), and also has
knowledge of SAP Enterprise portal (Administration), Java WebDynpros. He can also
contribute and modify applications in ABAP and ABAP WebDynpros.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 1

External Library Deployment and Usage in SAP NetWeaver Developer Studio (NWDS)

Table of Contents
Introduction ......................................................................................................................................................... 3
Add JAR to “External Library” type Development Component ........................................................................... 3
Step – Create Development Component “ExternalLibraryContainerDC” ....................................................... 3
Step – Add JAR library file to “ExternalLibraryContainerDC” ......................................................................... 5
Expose library to be used by other Development Components. ........................................................................ 6
Step - Add “public parts” to “ExternalLibraryContainerDC”. ............................................................................ 6
Step – Add JAR file to public part ................................................................................................................. 10
Create a deployable unit for “ExternalLibraryContainerDC” ............................................................................. 11
Step – Create a Development Component of type “J2EE server component -> Library”............................. 11
Step – Reference “ExternalLibraryContainerDC” from “externallibrary_deployableunit”. ............................. 12
Step - Built and deploy “externallibrary_deployableunit”. ............................................................................. 14
Step – Crosscheck whether it has reached server. ...................................................................................... 16
Using deployed library in your web application ................................................................................................ 17
Step – Create dependency to “externallibrary_deployableunit” from “WebApplicationDC_EA” ................... 17
Step – Create dependency to “ExternalLibraryContainerDC” from “WebApplicationDC_WA” ..................... 18
Step –Add reference to “Apache POI” in “WebApplicationDC_EA” .............................................................. 19
Related Contents .............................................................................................................................................. 23
Disclaimer and Liability Notice .......................................................................................................................... 24

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com
© 2010 SAP AG 2

com | UAC . This document will guide you through a step by step process for using an external library inside your existing web project. We will name it as  ExternalLibraryContainerDC Once we have a JAR inside above container (ExternalLibraryContainerDC). we need to deploy it on application server.com © 2010 SAP AG 3 .sdn. Like. Step – Create Development Component “ExternalLibraryContainerDC” Click on File -> New -> Other SAP COMMUNITY NETWORK SDN .sap.boc. External Library Deployment and Usage in SAP NetWeaver Developer Studio (NWDS) Introduction Often there are scenarios where inside your web application you need to reference some JAR file.bpx.sap. I assume that you already have your web development component and its corresponding deployment component (Enterprise Application Development Component) already created in your workspace. For this purpose we require a deployable unit for this library container DC of type “J2EE server component -> Library”.com | BPX . For this purpose you wish to use Apache POI Jar files.uac. you will learn how to deploy this JAR file in application server and then how to reference it from within your existing web development component.sap.com | BOC . you need to give download functionality in xlf format for your java report. I have named them:  WebApplicationDC_WA (Web Development Component)  WebApplicationDC_EA (Enterprise Application Development Component) In below step by step process we will create an “External Library” Development Component which will contain our JAR file. We will name it as  ExternalLibrary_DeployableUnit Add JAR to “External Library” type Development Component This component will act as actual container for our JAR file.sap. First.

bpx.sap.com © 2010 SAP AG 4 .com | UAC .sap.sdn.sap. External Library Deployment and Usage in SAP NetWeaver Developer Studio (NWDS) Select Development Component and click on Next.sap. Select Local Development -> My Components and click Next SAP COMMUNITY NETWORK SDN .uac.com | BOC .com | BPX .boc.

Select “External Library” as type of Development Component and click Finish Step – Add JAR library file to “ExternalLibraryContainerDC” Switch to “Package Explorer” in J2EE perspective.com | UAC . “Drag and Paste” your library in “Library folder” of ExternalLibraryContainerDC as shown below. You can use any other JAR file as well SAP COMMUNITY NETWORK SDN .sap. Note: Please note we are using “Apache POI” as an example.com | BOC .uac.sap.com © 2010 SAP AG 5 .sap. Component name “ExternalLibraryContainerDC”.bpx.com | BPX .sap. External Library Deployment and Usage in SAP NetWeaver Developer Studio (NWDS) Specify name of Vendor.sdn.boc.

Step . As the name suggest it is a part of Development Component which can be accessed from other Development Components.com | UAC .bpx.com | BOC .g.sap.sap. The place which we are referring to here is “Public Part”.sdn.boc.com © 2010 SAP AG 6 . we need to add this library to some place from where other Development Components (e. our web component “WebApplicationDC_WA”) can access it or reference it.sap.sap. Open “Development Configuration Perspective” and select Local Development -> My Components -> “ExternalLibraryContainerDC”. Enter name “AssemblyPublic” and click on “Finish” SAP COMMUNITY NETWORK SDN .com | BPX . Now.Add “public parts” to “ExternalLibraryContainerDC”. Till now we have successfully added our library to “ExternalLibraryContainerDC”. navigate to DC Metadata -> Public parts as shown below Right click on “Public parts” and select “New Public part”.uac. So now we will add “public parts” to “ExternalLibraryContainerDC”. External Library Deployment and Usage in SAP NetWeaver Developer Studio (NWDS) Expose library to be used by other Development Components. Now.

com | BOC . SAP COMMUNITY NETWORK SDN .com © 2010 SAP AG 7 .bpx.com | UAC .sap.sap.sap.boc.sap.com | BPX . External Library Deployment and Usage in SAP NetWeaver Developer Studio (NWDS) Create one more public part similarly and name it “CompilationPublic”.sdn.uac.

SAP COMMUNITY NETWORK SDN .boc. Select “AssemblyPublic” and update its purpose to “Assembly” in properties window as shown below. External Library Deployment and Usage in SAP NetWeaver Developer Studio (NWDS) Now you will be able to see two public parts under DC Metadata -> Public parts as shown below.sdn.com | BOC . Now we need to change an important property for public part “AssemblyPublic”.com | BPX .sap.com | UAC .sap.com © 2010 SAP AG 8 .sap.sap.bpx.uac.

sap.sdn. CompilationPublic) SAP COMMUNITY NETWORK SDN .sap.sap.bpx.com | BPX . External Library Deployment and Usage in SAP NetWeaver Developer Studio (NWDS) Next step will be to add your JAR file “Apache POI” to both these public parts (AssemblyPublic.boc.com | UAC .com © 2010 SAP AG 9 .com | BOC .sap.uac.

sap. SAP COMMUNITY NETWORK SDN . External Library Deployment and Usage in SAP NetWeaver Developer Studio (NWDS) Step – Add JAR file to public part Switch to “Package Explorer” in J2EE perspective. You will be prompted to select the required public part.sdn. Refer below figure.bpx. Select “CompilationPublic” Repeat same process for “AssemblyPublic”.sap.com | BOC .sap. And open folder “libraries” under “ExternalLibraryContainerDC” Development Component.com | BPX . Here you will find your uploaded JAR file.com | UAC .com © 2010 SAP AG 10 . Right click on “Apache POI” JAR file and navigate to “Development Component” -> “Add To Public part”.sap.uac.boc.

com | BPX .com | UAC . External Library Deployment and Usage in SAP NetWeaver Developer Studio (NWDS) Press “OK” Now.sdn. SAP COMMUNITY NETWORK SDN . we need to deploy this library to server.com | BOC .sap. it is now ready to be used by other Components.com © 2010 SAP AG 11 .boc. Now.uac.sap.bpx.sap. Create a deployable unit for “ExternalLibraryContainerDC” Our library is properly configured in Netweaver Developer Studio. For this we need a deployable unit which references to “ExternalLibraryContainerDC”. Name it as “externallibrary_deployableunit”. you have successfully added your JAR file to both public parts and thus. We will name this deployable unit as “ExternalLibrary_DeployableUnit” Step – Create a Development Component of type “J2EE server component -> Library” Create a new Development Component in your Local Development environment and select “J2EE server component -> Library” as type of project.sap.

sap.com | BOC . Step – Reference “ExternalLibraryContainerDC” from “externallibrary_deployableunit”.uac.sdn.sap. External Library Deployment and Usage in SAP NetWeaver Developer Studio (NWDS) Click Next and Finish. Add a “build” time dependency in “externallibrary_deployableunit” to assembly part “AssemblyPublic” of “ExternalLibraryContainerDC”.boc. Browse to “Used DCs” part of “externallibrary_deployableunit” Right click on “Used DCs” and click on “Add Used DC” Now in prompted window select Local Development -> “ExternalLibraryContainerDC” -> Public parts SAP COMMUNITY NETWORK SDN .com | BPX .sap.bpx.sap.com | UAC .com © 2010 SAP AG 12 .

com | UAC .sap.uac.com © 2010 SAP AG 13 .sap.bpx.boc.sdn. SAP COMMUNITY NETWORK SDN . External Library Deployment and Usage in SAP NetWeaver Developer Studio (NWDS) Select assembly public part “AssemblyPublic” Do not forget to select “Build Time” as dependency type.com | BOC .com | BPX .sap.sap.

sap.com © 2010 SAP AG 14 .com | BOC .sap.com | BPX .bpx.com | UAC . SAP COMMUNITY NETWORK SDN .boc. Step . “externallibrary_deployableunit”.sap.sap. External Library Deployment and Usage in SAP NetWeaver Developer Studio (NWDS) Click Finish and you will be able to see added public part to “Used DCs” portion of “ExternalLibraryContainerDC”. because of dependency we created it automatically asks to build “ExternalLibraryContainerDC”.e.Built and deploy “externallibrary_deployableunit”. As you will see.uac.sdn. Built the deployment unit for “ExternalLibraryContainerDC” i.

bpx.uac. SAP COMMUNITY NETWORK SDN . On successful deployment on server.sap.com | BPX .com | UAC . it will give a message in deploy output view.sap.com | BOC .sap.boc.sdn. External Library Deployment and Usage in SAP NetWeaver Developer Studio (NWDS) Click OK Now we will deploy it to server so that our “Apache POI” jar is available in server to be used by other components.com © 2010 SAP AG 15 .sap.

com | UAC . Open your J2EE server visual admin tool.com | BPX . External Library Deployment and Usage in SAP NetWeaver Developer Studio (NWDS) Step – Crosscheck whether it has reached server.sap.sap.com | BOC .com © 2010 SAP AG 16 .sap.bpx.uac.bat" Login and navigate to Server -> Libraries. You will find it in "<Installation Drive>:\Program Files\SAP\admin\go.boc. SAP COMMUNITY NETWORK SDN . Here you should be able to find “externallibrary_deployableunit”.sap.sdn. Click on it.

sap. External Library Deployment and Usage in SAP NetWeaver Developer Studio (NWDS) Using deployed library in your web application By now we have successfully configured and deployed our library “Apache POI” on server.boc.bpx. Right click there and select “Add Used DC” In prompted window navigate to “Local Development -> My Components -> externallibrary_deployableunit” Select “DC metadata -> Public Part -> <Public Part Name>” Select “Built time” and “Deploy time” as dependency type SAP COMMUNITY NETWORK SDN .sap. I have named them:  WebApplicationDC_WA (Web Development Component)  WebApplicationDC_EA (Enterprise Application Development Component) Step – Create dependency to “externallibrary_deployableunit” from “WebApplicationDC_EA” Open WebApplicationDC_EA in “J2EE DC Explorer” and navigate to “DC Metadata -> DC Definition -> Used DCs”. Note: I am assuming that you already have your web application and its deployable unit ready in your workspace.com | BPX . Now next step is to use this library in your web application.sap.com | UAC .sap.com © 2010 SAP AG 17 .com | BOC .uac.sdn.

boc.sdn. Right click there and select “Add Used DC”.sap.sap.com | UAC . External Library Deployment and Usage in SAP NetWeaver Developer Studio (NWDS) Click Finish.com | BOC .bpx.com © 2010 SAP AG 18 .sap. Step – Create dependency to “ExternalLibraryContainerDC” from “WebApplicationDC_WA” Open WebApplicationDC_WA in “J2EE DC Explorer” and navigate to “DC Metadata -> DC Definition -> Used DCs”.sap.uac. In prompted window navigate to “Local Development -> My Components -> ExternalLibraryContainerDC” Select “DC metadata -> Public Part -> CompilationPublic” SAP COMMUNITY NETWORK SDN .com | BPX .

xml”.com | BOC . In General tab select “References” and click on “Add” SAP COMMUNITY NETWORK SDN . Step –Add reference to “Apache POI” in “WebApplicationDC_EA” Open WebApplicationDC_EA in “J2EE DC Explorer”.sdn.uac.com | UAC . External Library Deployment and Usage in SAP NetWeaver Developer Studio (NWDS) Select “Built time” as dependency type Click Finish.sap. Navigate to “WebApplicationDC_EA -> Application-J2EE-Engine.sap.com © 2010 SAP AG 19 .xml” Open “Application-j2ee-engine.boc.com | BPX .bpx.sap.sap.

com | BPX .bpx. External Library Deployment and Usage in SAP NetWeaver Developer Studio (NWDS) In prompted window select “Select library/interface/service” Now select “externallibrary_deployableunit”.boc.com | BOC .uac.sap. SAP COMMUNITY NETWORK SDN .sap.com © 2010 SAP AG 20 .sap.sap.com | UAC . This is deployable unit for “ExternalLibraryContainerDC” which contains “Apache POI” jar file.sdn.

uac. External Library Deployment and Usage in SAP NetWeaver Developer Studio (NWDS) Click OK.com © 2010 SAP AG 21 .boc.sap.com | BPX .sap.com | BOC .sdn.sap.com | UAC . Note: Do not forget to save this application-j2ee-engine. Reference to jar file is now available with this development component.bpx.xml SAP COMMUNITY NETWORK SDN .sap.

sap.sap.sap. External Library Deployment and Usage in SAP NetWeaver Developer Studio (NWDS) Build and deploy “WebApplicationDC_EA” Your jar is now ready to be used by this web application.sap.boc.com | BPX .com | BOC .bpx.sdn.com | UAC .com © 2010 SAP AG 22 . SAP COMMUNITY NETWORK SDN .uac.

sap.sap.com | BOC .boc. SAP COMMUNITY NETWORK SDN .sap.sdn.com | UAC .uac.bpx. visit the Java homepage. External Library Deployment and Usage in SAP NetWeaver Developer Studio (NWDS) Related Contents For more information.com | BPX .sap.com © 2010 SAP AG 23 .

SAP will not be held liable for any damages caused by using or misusing the information.sdn. or seek to hold. Changes made based on this information are not supported and can be overwritten during an upgrade. External Library Deployment and Usage in SAP NetWeaver Developer Studio (NWDS) Disclaimer and Liability Notice This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supported by SAP. code or methods suggested in this document.com | BOC . You agree that you will not hold.uac.sap.bpx.sap.com | UAC . SAP COMMUNITY NETWORK SDN .com | BPX .sap. including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample. and anyone using these methods does so at his/her own risk.boc.sap.com © 2010 SAP AG 24 . SAP responsible or liable with respect to the content of this document.