cancel
Showing results for 
Search instead for 
Did you mean: 

How to use java classes of DC1 in DC2

jpenninkhof
Product and Topic Expert
Product and Topic Expert
0 Kudos

When I was trying to use a java-class from another DC, I stumbled into an error I didn't expect:

java.lang.NoClassDefFoundError: com/company/application/utils

This is what I did to get this far:

1. Created an empty Web Dynpro DC (DC1), to be used as a utilities library.

2. Added a Java class to the webdynpro project.

3. Added the class to a public part of type compilation.

4. Created a second Web Dynpro DC (DC2), which is supposed to consume the class from DC1.

5. Added a DC-usage relation, so that DC1 is in DC2's used DCs. In this usage-relation built-time and run-time were checked

5. Used DC1's class in DC2's component controller

6. Built both DCs and deployed them

7. Ran the application in DC2.

When I run the application, the application dumps a stack trace at the moment that and object is created based on the class in DC1.

Any idea how to get this working?

Accepted Solutions (1)

Accepted Solutions (1)

former_member190457
Contributor
0 Kudos

Hi,

please add your java class also to an assembly public part of your DC.

The other DC should declare a build dependency towards both public parts (api and assembly).

Kind regards,

Vincenzo

jpenninkhof
Product and Topic Expert
Product and Topic Expert
0 Kudos

please add your java class also to an assembly public part of your DC.

The other DC should declare a build dependency towards both public parts (api and assembly).

I've done that, but I'm afraid it didn't help...

former_member190457
Contributor
0 Kudos

Hi,

of course be aware that a rebuild for both DCs is required

Moreover, add to the public parts also:

package, package tree, file, folder with regard to your java class.

Let me know the outcome.

Regards

Vincenzo

jpenninkhof
Product and Topic Expert
Product and Topic Expert
0 Kudos

Moreover, add to the public parts also: package, package tree, file, folder with regard to your java class

I have added them all and rebuilt/deployed. I'm getting an error of a little bit different nature, but am not sure if it's getting worse or better...

java.lang.IllegalAccessError: tried to access method com.company.path.Class.Method()Ljava/lang/String; from class com.company.path.application

former_member190457
Contributor
0 Kudos

Hi, I assume you are using placeholders in your post instead of actual method/company names.

It looks much like a java-scope issue.

Could you elaborate on which kind of class (e.g. inner, extending superclass, ...) and method (protected, private, ...) you are calling and from where?

Regards, Vincenzo

jpenninkhof
Product and Topic Expert
Product and Topic Expert
0 Kudos

Vincenzo, here is the real error message:

java.lang.IllegalAccessError: tried to access method nl.phoqus.pataut.Guid.getGuidString()Ljava/lang/String; from class nl.phoqus.pataut.PatientAuthorization

I have inserted a very simple GUID generator that I used in a previous project. Please find the class file below:

package nl.phoqus.pataut;

import java.util.Random;

public class Guid {

	private static Guid guidFactory = new Guid();
	static Random random = new Random();

	/**
	 * Allow global replacement of the GUID generator.  Applications
	 * wishing to install their own GUID generators should sub-class
	 * Guid, override the getGuid() method, and use this method to
	 *  install their generator.
	 */

	public static void
	setGuidImpl(Guid factory) {
	guidFactory = factory;
	}

	/**
	 * Return a GUID as a string.
	 */

	public static String getString() {
	return guidFactory.getGuidString();
	}

	/**
	 * Return a GUID as a string.  This is completely arbitrary, and
	 * returns the hexification of a random value followed by a
	 * timestamp.
	 */

	protected String getGuidString() {
	   long rand = (random.nextLong() & 0x7FFFFFFFFFFFFFFFL) | 0x4000000000000000L;
	   return Long.toString(rand, 32) + Long.toString(System.currentTimeMillis()&0xFFFFFFFFFFFFFL, 32);
	}

}

I'm calling the class using the following statements from the component controller of DC2:

Guid x = new Guid();
String y = x.getGuidString();

The component controller resides in package package nl.phoqus.pataut.

Would that be the problem?

former_member190457
Contributor
0 Kudos

Indeed it's a java scope issue.

protected String getGuidString() -> the scope identifier 'protected' prevents you from accessing the method from a class that is not extending Guid.

You could just declare

public String getGuidString()

Let me know if things work out ok.

Regards

Vincenzo

jpenninkhof
Product and Topic Expert
Product and Topic Expert
0 Kudos

You could just declare public String getGuidString()

Because I copied it from a previous project, I just assumed it worked. Wrong assumption there.

After changing protected to public is now works.

Many thanks Vincenzo! Full points for you!

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

I would suggest to expose all the methods from the class using interface controller of DC1 and access them in DC2.

Regards

Ayyapparaj

jpenninkhof
Product and Topic Expert
Product and Topic Expert
0 Kudos

I would suggest to expose all the methods from the class using interface controller of DC1 and access them in DC2.

That would probably work, but it would lead to a lot of overhead. Besides, I can't imagine that it isn't possible to use a java class in another DC. There must be a way...

Former Member
0 Kudos

Hi,

If you want to use DC1 in DC2 then create public part of DC1 and then use the DC1 as used DC in DC2.

This will give reference to DC1.

Make sure you build DC1 properly.

Thanks,

Gopi

jpenninkhof
Product and Topic Expert
Product and Topic Expert
0 Kudos

If you want to use DC1 in DC2 then create public part of DC1 and then use the DC1 as used DC in DC2. This will give reference to DC1.

Yup, that's indeed what I did already.

Make sure you build DC1 properly.

DC1 was built properly.