Skip to Content
Author's profile photo Amritesh Kumar

Creating External Library and Using in DC

Creating External Library and Using in DC  

Version Details:

SAP Net Weaver Developer Studio (NWDS) version
7.01.00 and SAP Web Application Server (WAS) version 7.0.

Summary:

In this tutorial you learn how to use jar files in a Development Component (further referred as DC) using External Library. Since jar files added during development in class path are not deployable part of the DC so to make the jar files available at server end we are supposed to use External library.

15-pp15--3.5-.JPG

Author: Amritesh Kumar

Company:  Tata Technologies Limited (Pune)

 

Introduction

This tutorial shows you how to use create an External Library and use it with a DC

Prerequisites 

• Basic Java Programming 

• Basic Web Dynpro Hands-On experience about DC creation & Public Part

• We are creating the External Library on DTR and steps contains DTR activities so you must be logged in to DTR

Implementation 

Create Web External Library Project

Step 1: Create a Library Project with the name “ExtLib”.

/wp-content/uploads/2013/10/1_310969.jpg

Click on next, now if you are logged in to DTR activity window will appear.

Crate a new activity and click on ok button.

/wp-content/uploads/2013/10/3_311049.jpg

Activity is created now select the activity and click on ok button.

/wp-content/uploads/2013/10/4_311050.jpg

Step 2: Adding Jar Files

Open Navigator perspective (since it will not be visible in Web Dynpro Explorer) and explore the External Library project.

Now copy all the required jar files & paste in the “libraries” folder of the “ExtLib” project.

A window will appear asking add the jar to DTR. Select All & click on ok.

/wp-content/uploads/2013/10/5_311054.jpg

Select the Activity & click on ok.

/wp-content/uploads/2013/10/6_311055.jpg

Step 3: Create Public part & adding jar files to the public part.

 

Switch to Development Configuration Perspective.

/wp-content/uploads/2013/10/8_311057.jpg

  If it is not available there open from 

                 Window -> Open Perspective -> Other…

A window will appear, select Development configurations & click on ok.

/wp-content/uploads/2013/10/9_311068.jpg

Step 3.1

Now the following screen will appear.

Explore the “ExtLib” project & select “PublicParts”.

Now right click on this and click on “New Public Part”.

/wp-content/uploads/2013/10/10_311072.jpg

Now “Add Public Part” wizard will appear on the screen:

Select the first radio button (default it is selected).

Fill the “Name” caption & description are optional & click on finish.

/wp-content/uploads/2013/10/11_311074.jpg

Now it will ask again to add the files to DTR select the activity & ok.

/wp-content/uploads/2013/10/12_311078.jpg

/wp-content/uploads/2013/10/13_311079.jpg

Repeat Step 3.1 Step again, this time select second radio button of “Add Public Part Wizard”.

Give the “Name” and then finish & add the files to DTR again in the same activity.

/wp-content/uploads/2013/10/14_311084.jpg

Now again switch to Navigator perspective.

Select a jar file and right click on it and click on and select

           Development component -> Add to Public Part

/wp-content/uploads/2013/10/15_311085.jpg

Now following window will appear in which both the “Public Parts” we have already created will appear

/wp-content/uploads/2013/10/16_311086.jpg

Select the “Compilation” & click on ok.

So now the jar file is added to Compilation public part.

Like this add all the Jar files to both Compilation & Assembly Public parts.

Step 3: Build & Check in the External Library

Now again open the “Development Configurations Perspective”.

Select the “ExtLib” Project, right click & build another Build Development component window will appear select the project & click on ok.

/wp-content/uploads/2013/10/17_311090.jpg

   

/wp-content/uploads/2013/10/18_311092.jpg

Finally check in the activity by clicking on check in and the click on ok button of the check in popup.

/wp-content/uploads/2013/10/19_311093.jpg

/wp-content/uploads/2013/10/20_311095.jpg

 

External Library Created Successfully

Create New DC & Use External Library

Step 1: Create new DC

Since we assume that you have basic idea of creating DC we will just go through

 

Create a new DC

     File -> New Development Component

Select the track on which you want to create DC.

Give the Name of DC & Select the type WebDynpro & complete the wizard.

 

We have take DC name “Candidate” Inside a view we will write some test code for accessing KM resources which requires some jar  files which are available in our “ExtLib”.

Since we have not add external lib in our DC it will give error for imports

/wp-content/uploads/2013/10/21_311096.jpg

Step 2: Add External Library to our DC

Expand “Candidate” DC

DC MetaData -> DC Definition -> Used DCs

Now right click on “Used DCs” & click on “Add Used DC”

/wp-content/uploads/2013/10/22_311097.jpg

Click on “Add Used DC” it will ask for the activity.

Select the activity which we have already created during “Candidate” DC creation & click on ok.

“Add Dependency” window will appear.

Select the “Inactive” tab since our library is now activated up till now.

Now select the “ExtLib” explore it and inside “Public Parts” select both the public part “Assembly” & “Compilation” keep the dependency type build time & click on “Finish” button.

/wp-content/uploads/2013/10/24_311098.jpg

After adding used DC it will be showing in your use DC

/wp-content/uploads/2013/10/24_311098.jpg

Now right click on “Candidate” DC -> Development Components -> Sync used DCs

/wp-content/uploads/2013/10/25_311112.jpg

Step 3: Build the DC

It is strictly compulsory to build the DC only by the option “Build” which is available in

Right Click on DC “Candidate” => Development component => Build

Now you will find that errors showing imports are resolved now.

/wp-content/uploads/2013/10/26_311113.jpg

Step 3: Deploy the DC

It is strictly compulsory to “Deploy” the DC only by the option “Deploy” which is available in

Right Click on DC “Candidate” => Development component => Deploy

Note: If you use normal build & deploy option the external
library not gets deployed on server and will not be available to your DC.

So always use DC build & Deploy option.

Assigned Tags

      5 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Rajendrakumar Gaikwad
      Rajendrakumar Gaikwad

      Nice one Amritesh.

      Can you also hightlight  any issues we may face with this process and solutions to that?

      Regards

      Rajendra

      Author's profile photo Amritesh Kumar
      Amritesh Kumar
      Blog Post Author

      I faced some issues and listing frequently occurred mistakes :

      • Always use "Development Component -> Build" option to build

      and   "Development Component -> Deploy" to deploy the Project (Project is representing the project which is using the External Library). If you will used normal Deploy option it skips the External Library object from deployment.

      • Often we require to update our library (adding jar files) as per requirement. In such condition all the new jars must be added to both the Public Parts (Compilation & Assembly). Now the project who is referring this Library as Usage should sync with the library using "Development Component->Sync Used DCs" option. Finally use  "Development Component -> Build / Deploy" to build and deploy your project.
      • Don't forget to log on DTR 😉 since some of the options will not be available (Viz. Sync Used DCs).
      Author's profile photo Sharath M G
      Sharath M G

      Hello Amritesh,

      I feel that you have missed one step in the process of using external lib in a DC.

      Once you have build the library DC< you have to package it into a deploy-able java DC.

      This process will resolve the compile time errors. But at runtime, you will get NoClassDefFound error for the external library classes.

      Regards,

      Sharath

      Author's profile photo Amritesh Kumar
      Amritesh Kumar
      Blog Post Author

      Dear Sharath,

       

      Thanks for raising this point.

      If you will use normal "Deploy" option which gets displayed when we right click on the project, it excludes the "External Library" objects from your DC object deployment.

      But if you use "Development Component -> Deploy" option the external library object will be deployed on the server along with your DC object.

      Hope I have answered you doubt.

      Regards,

      Amritesh

      Author's profile photo Sharath M G
      Sharath M G

      Amritesh,

      I had a similar scenario but still had to package the extlib into a separate j2ee dc and deploy it on server.

      I will try once again if the deployment option has an impact.

      Thank you.

      Regards,

      Sharath