18
SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2009 SAP AG 1 Application Class Loading on SAP NetWeaver Explained – Running Hibernate Using the So-Called Heavy Resources Applies to Any SAP NetWeaver – Java release compliant with Java EE 5 and defining the so-called Heavy Resources, i.e. NetWeaver Composition Environment 7.1 and above. Any Java static library set – such as Hibernate 3.x. Summary This document discusses the basic concepts of the Application Class Loading on SAP NetWeaver Application Server – Java in the following often abbreviated as SAP NetWeaver Java Engine. It also exemplary describes how to run Hibernate using to so-called Heavy Resources of the Java Engine. This example will work with an arbitrary version of Hibernate and any version of the SAP NetWeaver Java Engine compliant with Java EE 5 and introducing the Heavy Resources, i.e. SAP NetWeaver Composition Environment 7.1 and above. This example is not Hibernate specific – the same pattern will work for any arbitrary Java static library set. Author: Goran Stoiljkovski Company: SAP AG Created on: 26 March 2009 Author Bio Goran Stoiljkovski is a solution architect whose main focus is on architecture and design of distributed computed systems and solutions. He is member of the global Co-Innovation Lab (COIL) team as part of the SAP Global Ecosystem and Partner Group.

Application Class Loading on SAP NetWeaver Explained ...€¦ · Any SAP NetWeaver – Java release compliant with Java EE 5 and defining the so-called Heavy Resources, i.e. NetWeaver

  • Upload
    others

  • View
    22

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Application Class Loading on SAP NetWeaver Explained ...€¦ · Any SAP NetWeaver – Java release compliant with Java EE 5 and defining the so-called Heavy Resources, i.e. NetWeaver

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

Application Class Loading on SAPNetWeaver Explained – RunningHibernate Using the So-CalledHeavy Resources

Applies toAny SAP NetWeaver – Java release compliant with Java EE 5 and defining the so-called Heavy Resources,i.e. NetWeaver Composition Environment 7.1 and above.

Any Java static library set – such as Hibernate 3.x.

SummaryThis document discusses the basic concepts of the Application Class Loading on SAP NetWeaverApplication Server – Java in the following often abbreviated as SAP NetWeaver Java Engine.

It also exemplary describes how to run Hibernate using to so-called Heavy Resources of the Java Engine.This example will work with an arbitrary version of Hibernate and any version of the SAP NetWeaver JavaEngine compliant with Java EE 5 and introducing the Heavy Resources, i.e. SAP NetWeaver CompositionEnvironment 7.1 and above.

This example is not Hibernate specific – the same pattern will work for any arbitrary Java static library set.

Author: Goran Stoiljkovski

Company: SAP AG

Created on: 26 March 2009

Author BioGoran Stoiljkovski is a solution architect whose main focus is on architecture and design ofdistributed computed systems and solutions. He is member of the global Co-Innovation Lab(COIL) team as part of the SAP Global Ecosystem and Partner Group.

Page 2: Application Class Loading on SAP NetWeaver Explained ...€¦ · Any SAP NetWeaver – Java release compliant with Java EE 5 and defining the so-called Heavy Resources, i.e. NetWeaver

Application Class Loading on SAP NetWeaver Explained – Running Hibernate Using the So-Called Heavy Resources

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

Table of ContentsApplication Class Loading on SAP NetWeaver Java......................................................................................3

Deploying Hibernate within the Application....................................................................................................4

Deploying Hibernate as a Heavy Resource Step-By-Step..............................................................................4Step 1 – Define a Web Module ..................................................................................................................5Step 2 – Define Application’s Enterprise Archive........................................................................................5Step 3 – Build References for the Application ............................................................................................6Step 4 – Check the Correctness of the Build Reference.............................................................................6Step 5 – Create the Heavy Resource Application.......................................................................................8Step 6 – Define Heavy Resource’s Specific Libraries ...............................................................................10Step 7 – Set Applications’ Class Loading References ..............................................................................12Step 8 – Check the Heavy Resources Configuration................................................................................12Step 9 – Deployment ...............................................................................................................................13Step 10 – Final Check .............................................................................................................................15Listing of Application-j2ee-engine.xml ......................................................................................................17

Copyright ....................................................................................................................................................18

Page 3: Application Class Loading on SAP NetWeaver Explained ...€¦ · Any SAP NetWeaver – Java release compliant with Java EE 5 and defining the so-called Heavy Resources, i.e. NetWeaver

Application Class Loading on SAP NetWeaver Explained – Running Hibernate Using the So-Called Heavy Resources

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com© 2009 SAP AG 3

Application Class Loading on SAP NetWeaver JavaThis section is a brief introduction to the application class loading of the NetWeaver Java Engine. Take alook at Figure 1 below – sketch based on Georgi Danov’s blog on SDN:https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/6447.

Figure 1

Let us roughly discuss this sketch for a moment:

Applications on the NetWeaver platform are loaded with an Application Class Loader – and thereis one and only one per application. An Enterprise Archive (EAR) can be identified with anapplication.

As a basic principle, the NetWeaver follows the parent-first class loading pattern. As aconsequence, this also means that if a class is to be loaded, NetWeaver looks for an alreadyavailable instance of that class/object. The class loading hierarchy is prioritized according to Figure1 – the lower numbers in the class loading graph always win against the higher ones.

One observes that i.e. the Default References win against the application references and theapplication resources. The Default References also hold a reference to the Core Engine classes.

The application references are a feature of NetWeaver. As there can only be one class loader perapplication, NetWeaver has defined the application references in order to load resources (not onlyclasses) from other applications. This app-to-app reference is set in the vendor specificapplication-j2ee-engine.xml descriptor of the referencing application. The reference is – so tospeak – set as “referencingApp referencedApp”.

The Application Resources class loader loads the resources defined in the application context –everything that is in the EAR of that application.

The Heavy Resources are a class loading concept specific to the SAP NetWeaver Java andintroduced just recently. They allow for defining flexible runtime class loading of resources deployedon the platform. The Heavy Resources define resources, which are loaded with a top priority in theclass loading graph among all the resources previously mentioned. If an application is to beconsidered as Heavy Resource by NetWeaver, one has to “switch it on”. This is a property of theapplication (the EAR) controlled by a vendor specific descriptor called application-service.xmlcontained in the EAR. But note that this property is defined only for SAP Java EE 5 compliantarchives/applications.

Page 4: Application Class Loading on SAP NetWeaver Explained ...€¦ · Any SAP NetWeaver – Java release compliant with Java EE 5 and defining the so-called Heavy Resources, i.e. NetWeaver

Application Class Loading on SAP NetWeaver Explained – Running Hibernate Using the So-Called Heavy Resources

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com© 2009 SAP AG 4

Note: One usually and per default deploys applications without switching on the heavy resources – and this is the usecase that occasionally bears some disadvantages. We will discuss the answers to these dilemmas in the nextsection.

Deploying Hibernate within the ApplicationOK, that was a short introduction to the class loading architecture of the NetWeaver Java Engine. With this inmind, let us explain what happens, if one deploys Hibernate in the application context, i.e. as part of theapplication’s EAR.

Note: This is probably the way most people would view as the most pragmatic one for running Hibernate on the SAPJava Engine – unfortunately. Deploying Hibernate within the application (as part of the application’s EAR) will mostlikely end up with runtime errors/exceptions of/in the application, which of course is not the desired result.

This is the reason why:

The Hibernate binary package comes with a lot of helper libraries – even in the core version onefinds i.e. DOM4J, ANTLR, etc.

A version of ANTLR is also included in the core libraries of SAP NetWeaver. This version of ANTLRis loaded with the default references and is so to speak of priority 2. If one puts the Hibernatepackage –and thus also the accompanying ANTLR library – in the EAR, this library will be loadedwith priority 4. This means that in this case the ANTLR library delivered with the server is alwaysloaded before the ANTLR library coming along with the application (Hibernate package). The resultsare runtime exceptions of type ClassCastException, ClassNotFoundException, etc, or even moresevere errors like ClassDefNotFoundError thrown by instances trying to invoke or cast to ANTLRclasses.

The way out of this dilemma is to extract the Hibernate package out of the application and deploy itas a “heavy reference application”. The “actual” application then references this “heavy referenceapplication” and everything is fine.

In the following section we will describe this process step-by-step.

Deploying Hibernate as a Heavy Resource Step-By-StepHere a detailed description of that process using the SAP NetWeaver Developer Studio. We will reassembleyour application to consist of the following three archives

An enterprise application (EAR) called YourApp – without Hibernate so to speak

A web module (WAR) included in the YourApp’s enterprise archive called YourWebModule

And a Java EE 5 compliant enterprise application (EAR) called Hibernate containing solely theHibernate package.

Page 5: Application Class Loading on SAP NetWeaver Explained ...€¦ · Any SAP NetWeaver – Java release compliant with Java EE 5 and defining the so-called Heavy Resources, i.e. NetWeaver

Application Class Loading on SAP NetWeaver Explained – Running Hibernate Using the So-Called Heavy Resources

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com© 2009 SAP AG 5

Step 1 – Define a Web Module

You define a web module (in thiscase called YourWebModule) andthere you put all the application’sresources – the ones for the webapplication as well as theapplication’s logic. In this case youmay view the my-app.jar as alibrary containing the application’slogic (business or control logic).

Navigation: New Project WebDynamic Web Project.

Step 2 – Define Application’sEnterprise Archive

You define an enterpriseapplication via the EnterpriseApplication Project in the creationwizard. The project name is theapplication’s name YourApp.

Navigation: New ProjectJ2EE Enterprise ApplicationProject

Page 6: Application Class Loading on SAP NetWeaver Explained ...€¦ · Any SAP NetWeaver – Java release compliant with Java EE 5 and defining the so-called Heavy Resources, i.e. NetWeaver

Application Class Loading on SAP NetWeaver Explained – Running Hibernate Using the So-Called Heavy Resources

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com© 2009 SAP AG 6

Step 3 – Build References for theApplication

Set a “build” reference to your webapplication, so the newest webmodule is included in theapplication module every time youbuild the enterprise application.

Step 4 – Check the Correctnessof the Build Reference

You can check if this reference isset correctly by exporting the earfile to the file system. Unzip the*.ear file to check if the *.warfile is included.

Navigation: New Export SAPEAR File.

Page 7: Application Class Loading on SAP NetWeaver Explained ...€¦ · Any SAP NetWeaver – Java release compliant with Java EE 5 and defining the so-called Heavy Resources, i.e. NetWeaver

Application Class Loading on SAP NetWeaver Explained – Running Hibernate Using the So-Called Heavy Resources

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com© 2009 SAP AG 7

If you export the file on the rootlevel of your enterprise application,you will also see it in the IDE(NetWeaver Developer Studio)

Page 8: Application Class Loading on SAP NetWeaver Explained ...€¦ · Any SAP NetWeaver – Java release compliant with Java EE 5 and defining the so-called Heavy Resources, i.e. NetWeaver

Application Class Loading on SAP NetWeaver Explained – Running Hibernate Using the So-Called Heavy Resources

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com© 2009 SAP AG 8

Step 5 – Create the HeavyResource Application

Create your second enterpriseapplication project (Hibernate). Inthis case you have to make sureyou define this project as “SAPEAR Java EE 5 Project”.

IMPORTANT: This is necessarysince the “heavy references” workonly for Java EE 5 applications!

Make sure that the property “SAPApplication Library Container” ischecked. This is a property forSAP’s deployment and runtimemanagement. This way thedeployed enterprise application (inthis case Hibernate) is marked as a“heavy resource”.

Page 9: Application Class Loading on SAP NetWeaver Explained ...€¦ · Any SAP NetWeaver – Java release compliant with Java EE 5 and defining the so-called Heavy Resources, i.e. NetWeaver

Application Class Loading on SAP NetWeaver Explained – Running Hibernate Using the So-Called Heavy Resources

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com© 2009 SAP AG 9

Please do not add any webmodules in this application – eventhough the IDE will recognize theweb modules in your openworkspace and will ask if you wantto add them to your enterpriseapplication.

Name your application“Hibernate”.

This is the result viewed in the IDE.

You can also see the SAP JavaEngine specific descriptorapplication-service.xmlneeded for the application to bemarked as a heavy resource.

Page 10: Application Class Loading on SAP NetWeaver Explained ...€¦ · Any SAP NetWeaver – Java release compliant with Java EE 5 and defining the so-called Heavy Resources, i.e. NetWeaver

Application Class Loading on SAP NetWeaver Explained – Running Hibernate Using the So-Called Heavy Resources

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com© 2009 SAP AG 10

Step 6 – Define HeavyResource’s Specific Libraries

Now you have to add the Hibernatespecific libraries to this EAR.

Go to the context menu of theHibernate project and call thePreferences. Click on the item“Bundled Libraries” and then “AddExternal Jars” from the file systemwhere they are located.

This is a list of JARs we add to ourHibernate project. In your case thislist may be much longer dependingon Hibernate’s flavor you are usingin your application. We exemplarilyused the basic version.

Page 11: Application Class Loading on SAP NetWeaver Explained ...€¦ · Any SAP NetWeaver – Java release compliant with Java EE 5 and defining the so-called Heavy Resources, i.e. NetWeaver

Application Class Loading on SAP NetWeaver Explained – Running Hibernate Using the So-Called Heavy Resources

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com© 2009 SAP AG 11

This is what you will see after thisstep. Complete the import bysaying “OK”.

Page 12: Application Class Loading on SAP NetWeaver Explained ...€¦ · Any SAP NetWeaver – Java release compliant with Java EE 5 and defining the so-called Heavy Resources, i.e. NetWeaver

Application Class Loading on SAP NetWeaver Explained – Running Hibernate Using the So-Called Heavy Resources

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com© 2009 SAP AG 12

Step 7 – Set Applications’ ClassLoading References

Now you have to set a referencefrom your application YourApp tothe Hibernate application. This isdone by editing the descriptorapplication-j2ee-engine.xml ofthe referencing application and thatis YourApp.

You will find the listing of this file atthe end of this document.

For the meaning of the XMLtags/elements and their attributesplease refer to the onlinedocumentation onhttp://help.sap.com

Step 8 – Check the HeavyResources Configuration

Before you deploy yourapplications to the Java Engine –and especially the Hibernateapplication – you should make surethat the version of the Engine youare running is configured fordeployment of the heavyresources. This configuration is adefault in newest versions of theengine, so most likely you will nothave to change anything.

Open the offline Config Toollocated in the <install-home>\<instance-name>\j2ee\configtool and start theconfigtool.bat. Connect to thesystem database and go toServices library_container. Youshould set the“Define_Heavy_Resources”property to “true” if not already set.

Page 13: Application Class Loading on SAP NetWeaver Explained ...€¦ · Any SAP NetWeaver – Java release compliant with Java EE 5 and defining the so-called Heavy Resources, i.e. NetWeaver

Application Class Loading on SAP NetWeaver Explained – Running Hibernate Using the So-Called Heavy Resources

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com© 2009 SAP AG 13

Step 9 – Deployment

Now you have to deploy yourapplications. Remember that youhave two applications: Hibernateand YourApp.

Make sure that your IDE knows theserver you are deploying to. Youcan check that in WindowPreferences SAP AS Java.

Since YourApp is has a hardreference to the Hibernateapplication, you will have to deployHibernate first.

In the IDE right-click the Hibernateproject and go to Run As Runon Server.

You will get a message (a pop-upwindow) about the successfuldeployment of your Hibernateapplication.

Page 14: Application Class Loading on SAP NetWeaver Explained ...€¦ · Any SAP NetWeaver – Java release compliant with Java EE 5 and defining the so-called Heavy Resources, i.e. NetWeaver

Application Class Loading on SAP NetWeaver Explained – Running Hibernate Using the So-Called Heavy Resources

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com© 2009 SAP AG 14

In the same way deploy theYouApp application.

That’s it! You have successfullyperformed the deployment of bothapplications.

Page 15: Application Class Loading on SAP NetWeaver Explained ...€¦ · Any SAP NetWeaver – Java release compliant with Java EE 5 and defining the so-called Heavy Resources, i.e. NetWeaver

Application Class Loading on SAP NetWeaver Explained – Running Hibernate Using the So-Called Heavy Resources

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com© 2009 SAP AG 15

Step 10 – Final Check

Now you should check if everythingis in place – especially if theHibernate application wassuccessfully deployed as a HeavyResource.

Logon to the server via telnet. Bearin mind that telnet does not workremotely but only on the localmachine, where your Java Engineis running.

List your Hibernate application byexecuting the list_app command.You can grep for your Hibernateapplication and thus avoid listing allthe applications deployed on theengine:

list_app | grep Hibern

You will see the status of theapplication, which should be“started”.

Now you can see if the Hibernateapplication was deployed as aheavy resource. Execute thecommand (ll = list libraries)

ll | grep Hibernate

The last line confirms thatHibernate was deployed as aheavy resource.

Page 16: Application Class Loading on SAP NetWeaver Explained ...€¦ · Any SAP NetWeaver – Java release compliant with Java EE 5 and defining the so-called Heavy Resources, i.e. NetWeaver

Application Class Loading on SAP NetWeaver Explained – Running Hibernate Using the So-Called Heavy Resources

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com© 2009 SAP AG 16

Now you should check if all thedesired jars are part or theHibernate application

llr com.sap/Hibernate-library-loader

This command lists the associatedresources (JARs) with the heavyresource Hibernate.

That is all.

Page 17: Application Class Loading on SAP NetWeaver Explained ...€¦ · Any SAP NetWeaver – Java release compliant with Java EE 5 and defining the so-called Heavy Resources, i.e. NetWeaver

Application Class Loading on SAP NetWeaver Explained – Running Hibernate Using the So-Called Heavy Resources

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com© 2009 SAP AG 17

Listing of Application-j2ee-engine.xml

<?xml version="1.0" encoding="UTF-8"?>

<application-j2ee-engine xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:noNamespaceSchemaLocation="application-j2ee-engine.xsd">

<reference reference-type="hard">

<reference-target provider-name="com.sap"

target-type="application">Hibernate</reference-target>

</reference>

<provider-name>com.sap</provider-name>

<fail-over-enable

mode="disable"

xsi:type="fail-over-enableType_disable"/>

<start-up

mode="always"/>

</application-j2ee-engine>

Page 18: Application Class Loading on SAP NetWeaver Explained ...€¦ · Any SAP NetWeaver – Java release compliant with Java EE 5 and defining the so-called Heavy Resources, i.e. NetWeaver

Application Class Loading on SAP NetWeaver Explained – Running Hibernate Using the So-Called Heavy Resources

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com© 2009 SAP AG 18

Copyright© Copyright 2009 SAP AG. All rights reserved.

No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG.The information contained herein may be changed without prior notice.

Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.

Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.

IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10, z9,iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server,PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER, OpenPower, PowerPC, BatchPipes,BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX,Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of IBM Corporation.

Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.

Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe SystemsIncorporated in the United States and/or other countries.

Oracle is a registered trademark of Oracle Corporation.

UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.

Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks ofCitrix Systems, Inc.

HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C®, World Wide Web Consortium, MassachusettsInstitute of Technology.

Java is a registered trademark of Sun Microsystems, Inc.

JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented byNetscape.

SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, and other SAP products and services mentionedherein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries.

Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, andother Business Objects products and services mentioned herein as well as their respective logos are trademarks or registeredtrademarks of Business Objects S.A. in the United States and in other countries. Business Objects is an SAP company.

All other product and service names mentioned are the trademarks of their respective companies. Data contained in this documentserves informational purposes only. National product specifications may vary.

These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAPGroup") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors oromissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in theexpress warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting anadditional warranty.