A bit of (impractical) scripting for Web Dynpro
Introduction
There are a lot of messages on SDN forums regarding using third-party libraries in SAP J2EE applications. Also there is a complete section available at http://help.sap.com, many developers either find it incomplete or cannot find it at all (I bet majority even don’t try to search, but this is different topic).
Below is step-by-step guide how to deploy Rhino JavaScript interpreter library to J2EE server and use it in WebDynpro application.</p>
Step 0. Preparation
First download latest Rhino build from mozilla.org and extract
js.jar
file from Zip archive. Mozilla download page contains broken links, here is direct link to Rhino 1.6 R2 / RC2 .
Next, activate “Development Configurations” perpective in NetWeaver IDE (use menu path: “Window -> Open Perpective -> Other…”). We will create all necessary development components (DC for short) in Local Development / My Components branch.
Activate “Development Configurations” view.
Step 1. Create and build “External Library”
Switch to “Development Configurations” perpective if you are not already there, drill down to “Local Development -> My Components”, right-click and select “Create New DC…” command
Running “Create New DC…” dialog.
Now fill in all necessary fields as shown below and click finish.
Create “External Library” DC.
IDE will create and open automatically necessary project. In root project directory find a folder
libraries
(in my environment NetWeaver shows it in project tree, but does not create it on disk – just create it manually). Now copy
js.jar
from Rhino distribution here. Next, select
library
folder in IDE, right-click on it and call “Refresh” command.
After IDE synchronized changes with file system, right-click on jar file in tree and select “Development Component -> Add To Public Part”
Adding Aarchive (js.jar) to public part
NetWeaver pre-create
ExternalLibs
public part for this type of projects, so simply select it in appeared dialog and click “OK”. Afterwards right-click on project itself and run command “Development Component -> Build”. Step complete.
Step 2. Create, build, deploy “J2EE Server / Library”
After we have created and built
External Library
DC we need to deploy it to SAP J2EE server somehow. So next create “J2EE Server Component / Library” DC:
Create “J2EE Server Component / Library” DC
Note that during project createion NetWeaver IDE may prompt you to open
JEE Development Perspective
. Just agree with it. Along this it will open
J2EE DC Explorer
view (switch to this view yourself if this doesn’t happen). Now expand project structure to “DC Metadata -> DC Definition -> Used DCs”. Activate contextual menu on last node and invoke “Add Used DC…”. Add reference to the public part of previously created
Extrenal Library
here. Note, that you have to specify both build time and run-time dependency here. Otherwise created SDA file will not contain js.jar from external library.
Add used DC (External Library) to J2EE library
It is time to build the project and analyze results. First of all you have to check generated SDA file in
gen/default/deploy
folder. Verify that it contains
js.jar
. Now something interesting. Go to
gen/default/public
folder. You should find here
defLib
folder. Yes, NetWeaver IDE again created public part, this time it is
defLib
. And if you drill down to
gen/default/plublic/defLib/lib/java
then you meet
js.jar
file again.
From now you may refere this (defLib) public part in the rest of SAP J2EE projects. But before we have to deploy it!. So, context menu on SAP J2EE Component / Library project, “Development Component -> Deploy”. Everything should go smoothly, let us verify results and run Visual Administrator:
Scroll to Libraries node
JavaScript (Rhino) Library Deployed
Step 3. Create WebDynpro Development Component
Now you may refer JavaScript library from any J2EE project. Obviously, that I wiil use it from WebDynpro π
So, two initial tasks should be known for you: we will create WebDynpro Development Component and add
defLib
public part of
js/lib
DC to it (the only difference is that here build-time dependency is enough):
Create “WebDynpro” DC.
Add used DC (defLib) to WebDynpro DC
However, WebDynpro project will not contain JavaScript library files (as in case with J2EE library). So we have to define
reference
to aforementioned library to let class loader find necessary classes at run-time. Run contextual menu on project root in IDE and select “Properties”, then switch to “WebDynpro References ->
Library references” and add “mozilla.orgjslib” (you may see the name in Visual Administrator):
Heck, we “invent” tool before task π If anyone has ideas how scripting could be applied in WebDynpro you are welcome to share your thoughts in comments!</p>
Some remarks:
My studio does not create it. You have create it manually with "Purpose" "Assembly".
Nothing there but it is not a problem. SDA contains jar and everything is working.
Best regards, Maksim Rashchynski.
Thanks for pointing this out.
However, it's quite strange -- my environment is SP11 and yours is of higher version...
VS
Can we extract URL parameters from URL and bind it to the context in the Web Dynpro application.
For eg:
If I have URL which has
param=value as FileName=One needs to read value of param 'FileName' and store 'One' in the context.
Can the below be implemented in Web Dynpro
For http://example.com/page.html?a=xxx, the two lines below should return the value after the "=" for the variable "xxx":
fullurl = parent.document.url
xxx = fullurl.substring(fullurl.indexOf('?')+3, fullurl.length)
It says to "Take the text string of the url. Use a substring beginning three past the position of the "?" and going through the end of the text string.
I am trying to use an external JAR in my WDApp. I am able to build and deploy the app but not able to run it. Getting a well known " java.lang.NoClassDefFoundError" error.
1.Followed your steps and created 2 DCs(DCjar and DClib)
2.Created a WebDynpro DC and attached DCjar as used DC.
3.written my code which has some references to the above library(added library reference). Was able to build and deploy the app.
4.Tried running the app but came with the error mentioned above.
an interesting thing that I noticed was I went though Visual Administrator selected the above library abut there was no file under JARs Contained.
Can you please point me in the right direction if you can.
Thanks,
Sanath
I am having the same problem. Were you able to solve it?
Thanks,
Arvind
I also faced the same error java.lang.NoClassDefFoundError.
Did you guys find any solution to this error?
Ashish Shah
Those of you who want to refer to this Java library from EJB or other Web Projects may take a look at this link:
http://help.sap.com/saphelp_nw04/helpdata/en/83/82814282cfc153e10000000a1550b0/frameset.htm
Ashish Shah
The SP11 IDE automatically created a compilation public part and also marked the DC as "external" (you can see a tag in the .dcdef file). Due to this flag the public part is actually treated as both compilation and assembly public part at the same time (which can be rather confusing).
Starting with SP12, the IDE does neither automatically create a public part, nor does it mark the DC as "external" anymore. This means that the developer is responsible for creating and filling appropriate compilation and/or assembly public parts.
Best regards,
Marc
Yes this is an issue, and, btw, Maksim pointed out about differences even within SP11 <-> SP12 versions.
Thank you for comment -- it helps this blog post to stay up to date π
VS
Please, Can you tell me how can I do that?
Thanks in advance.
Martin
Can you tell me how can I do that?
Thanks in advance.
Martin
Before starting to work with Netweaver I did Java web development for 6 years. It's been an extremely frustrating experience to learn the SAP-way of things. I spent the first year fighting it but I'm at the point now where I just want to understand it.
But it's still very frustrating because things just aren't consistent.
The process covered in this blog is a perfect example. For the last year and a half we've been doing normal (not web dynpro) web development using Netweaver. We use external libraries as well as 'common code' that we expose as Public Parts.
The process we use to include those in our web projects is very different from the process I'm finding has to be used for Web Dynpro apps.
Now, WHY couldn't SAP have made those consistent?
Sorry for the rant. It's just so frustrating. It feels like I spend more time configuring than actually developing.
Anyway, thanks Valery for the blog. I found it helpful as well as a lot of your posts on the forums.
David.
I noticed that on your screen print of the "Add Dependency" dialog box you have the "Run Time" box checked and have "strong" selected in the "runtime qualifier" dropdown.
When I've done this in my web apps (non-web dynpro) I've always just selected the "Build Time" and "Deploy Time" boxes. I've always left the "Run Time" and "runtime qualifier" to their default values (unselected and blank respectively)
As I've said before, that works fine in web apps. Is the "Run Time" and "strong" requirements for web dynpro apps? If so, would you be able to explain why the difference?
Thanks again!
The blog seems to be good.I still have some doubts here.
If we have 2 applications (ear's) and there is a dependency between them. Do we put it through used DC with a run time checkbox selected or through application references or both. Can anyone explain the difference in detail.It sounds so confusing
Shashank
Dear Valery and SDN members,<br/><br/>I think your blog really helped me to use the external jar files in Webdynpro DC. I'm still trying to catch up with what's discussed. Here is my problem:<br/><br/>NW 04s SP12, NWDS Version: 7.0.09 <br/><br/>I have a project SCMDashboard which is suppose to be entered in NWDI and run on Dev, Test, Prod (no Cons). Also there is a sandbox that has no relation to JDI<br/><br/>In my project I have 2 Deployable DCs:<br/>(1) <br/>-WebDynPro DC app/scmticon , vendor sap.com<br/> it has app/securityLib(defLib) as Used DC<br/>This DC is build into .ear <br/><br/>The Project Properties=> WebDynpro References=> Libraries References point to: app~securityLib (what Visual Admin shows as a DC name)<br/><br/>(2)<br/>Based on Valery Silaev's blog I made 2 following DCs.<br/><br/>-J2EE Server Library DC app/securityLib, vendor sap.com<br/> it has app/security(poi3_compile), app/security(poi3_assembly), app/security(secur_compile), app/security(secur_assembly) used DCs<br/>This DC is successfully build into .sda file with warninggs:<br/><Warning: No runtime information available for development component type External Library (sap.com), cannot validate runtime dependency.<br/>and deployed.>- External Library type of DC is not deployable and has no runtime info, that's why it got this message,I guess. The actual .sda has 2 jars in it<br/><br/>(3) External library DC app/security<br/>This one has 2 jar files and 2x(compile+assembly)=4 public parts<br/><br/><br/>The project runs successfully on Sandbox and Dev. DC(1) uses the classes of 2 jars that reside in DC(2).<br/><br/>!!!ERROR!!!!! After assembly into DASHBOARD_SC .sca successfully and import/deploy into Test, the DC1 cannot find the DC2 (java.lang.NoClassDefFoundError).<br/>I think after assembly the reference of DC2 become broken or .SDA is missing inside the assembled .sca.<br/>I haven't looked at .sca file yet cause I don't have an access to transport dir/CMS/archives/ *.sca<br/>Do you have any thoughts on this issue?<br/>Thank you for you attention and time.<br/><br/>Leonid Litvak<br/>
java.lang.NoClassDefFoundError
should look at sap note 95826 , 91238,935334,833415
and the thread
Jars not included in J2EE Library DC SDA
Ashish
thank you very much. This blog is really helpful.
Because of the version (NW04s SP13) i need to use also solution proposed here (for those who will have similar troubles):
Bid adieu to bots - using CAPTCHAs
Dan
One example of a possible appplication for your WDP Javascript interpreter would be the use of the Google Maps API in WDP-applications!
SAPJ2EE::library:sap.com~... or
PORTAL:sap.com/...