cancel
Showing results for 
Search instead for 
Did you mean: 

java.lang.ClassCastException - External Library DC

Former Member
0 Kudos

Hi All

1. I created a simple class (Address with setters and getters) and made it as jar.

2. I added this jar to External Library DC.

3. I created 2 Public Parts. Each with Assembly (Runtime- STrong) and compilation (Build)

4. I added this DC as USED DC for another DC's which are a portal application standalone DC (1 with portal application and another as portal service).

5. Service application is returning the Address object to the calling portal application DC.

6. When i catch the object from my service at my component Earlier i got classnofound error. but its gone once i got the ASSEMBLY PP.

<b>7. Now i get the

java.lang.ClassCastException

for the Address (class) com/xxx/Address incompatible with com/xxx//Address</b>

I really dont undestand what else do we need to make sure that there is no typecast problem.

<u><b>Bottom line: When calling External Library JAR's class at portal application, ClassCastException is coming</b></u>

Thanks,

Raghavendra Pothula

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Use a J2EE Library to deploy the External library DC. Then reference the J2EE Library as a sharing reference in your portal applications.

Former Member
0 Kudos

Hi Pascal,

As you said i created the J2EE Library DC. But i am not figuring where to copy the JAR file in this DC Project. As there is no folde for LIB. And if i copy the JAR in the root folder of project , then i am not able to add it to Public Reference defLib.

could you pls let me know how to add JAR file to J2EE Library DC and Also add it to the Public Reference.

Thanks,

Raghavendra Pothula

Former Member
0 Kudos

Thanks Madou & Pascal!!!

The problem is almost solved. I mean i able to avoid the exception. I am able get/pass Objects from portal service DC to portal application DC using External Library DC which is encapsulated in the J2EE Library DC.

But the problem which is wierd..

- I am able to the object ADDRESS from the service and able to catch in the DynPage Class. This works perfectly, i mean i am geting the right values from that object.

- Now in the Dynpage class i am storing this ADDRESS Object in the session and calling the DynPageJSPPage

- In the DynPageJSP i am creating the ADDRESS Object and assigning the object from session which is sent by DYnPageClass.

- At runtime i am getting error saying ADDRESS - cannot find symbol. For that package its saying that package.....doesnt exist

I dont know how the same application is compile & runtime free for JspDynpageClass and Runtime error for JSPDynpageJSP Page.

If it should fail., then both shouldnt work..

Please let me know where can i gone wrong???

<b><u>Currently i did like this:</u></b>

1. External DC with <u>Compile & Assembly PPs</u>

2. J2EE Library DC - Used DC=>External DC-><u>Compile (Build)& Assembly(Build-Runtime) PPs (both)</u>

3. Service Portal DC- <u>Used DC=>J2EE Library DC - defLib PP(Build), Added SharingReference to J2EE Library DC</u>

4. Client Portal App DC=><u>J2EE Library DC- defLib PP(Build), Service Portal DC (API) Build time, Added Sharing Reference for both Service Portal DC & J2EE Library DC</u>

I dont get any idea.. where is the bug!!

Thanks for your time,

Raghavendra Pothula

Sigiswald
Contributor
0 Kudos

Hi Raghavendra,

I checked both approaches you tried and they both seem fine. Hard to tell what goes wrong... (In the 2nd approach you get the problem "cannot find symbol"; you did define an import statement at the top of your jsp? e.g. <i><%@page import="com.company.app.Address"%></i>)

Let's try another, much more simple approach.

1. Create the portal service DC and include the Address class in that DC itself (in the src.api directory).

2. Create the client portal app DC and define a sharing reference to the 1st DC.

I assume this should work too. But maybe I forget something trivial here; it just seems too easy...

Kind regards,

Sigiswald

Former Member
0 Kudos

When you use the J2EE Library DC, you do not need the Service Portal DC anymore. You might be confusing the classloader, since in your current configuration you will actually have two references to the jars in your External Library DC. So I recommend to remove the Used DC and Sharing Reference to the Service DC from the Client DC.

Sigiswald
Contributor
0 Kudos

Hi Raghavendra,

The reason of the ClassCastException is that the external library jar file is deployed with both (portal + service) applications and both applications have their own classloader.

So when the service application creates an Address object, it is loaded with the classloader of the service application. The complete namespace of the Address object is actually <service application classloader>.com.xxx.Address. And when the portal application receives the Address object, it tries to load it with its own classloader, or cast it to <portal application classloader>.com.xxx.Address.

Essentially, when passing objects across applications (deployable units), you must ensure the object being passed is deployed only once.

We have an external library DC that has two public parts: lib-api and lib-assembly. All our standard Web Dynpro applications have a usage dependency on the lib-api public part only and have a sharing reference to another, special purpose Web Dynpro application. That special purpose Web Dynpro application is the only Web Dynpro application that has a usage dependency on the lib-assembly public part (and that's actually the only purpose it has).

I suppose you can use a similar construction with portal applications.

Kind regards,

Sigiswald

Former Member
0 Kudos

Hi Madou,

As you said, I created another Portal App DC. Now i have below, with these links

1. <b>External DC -</b> <u>compile-API, assembly-API</u>

2.<b> Special Portal App DC -</b> <u>UsedDC=>External DC - with assembly-API</u>

3. <b>Service Portal App DC -</b> <u>UsedDC =>ExternalDC with compil-API PP</u>, AND <u>Sharing Reference => Special Portal App DC</u> - I have just added this to PortalApp.xml not made special DC as used.

4. <b>Service Client Portal App DC -</b> <u>UsedDC =>ExternalDC with compile-API</u> PP and <u>Sharing Reference => Special Portal App, Service Portal App DC</u>

Now i am <u>getting the runtime error - NoClassFound Error from the (3)Service Portal App DC</u>. It is unable to get the ADDRESS class reference at runtime from the Sharing Reference of Special App DC. Inspite of adding the sharing refernece

Please let me know where have i gone wrong

Thanks,

Raghavendra Pothula