12 Replies Latest reply: Nov 21, 2008 4:42 PM by Jan Penninkhof RSS

How to use java classes of DC1 in DC2

Jan Penninkhof
Currently Being Moderated

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?

  • Re: How to use java classes of DC1 in DC2
    VINCENZO TURCO
    Currently Being Moderated

    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

    • Re: How to use java classes of DC1 in DC2
      Jan Penninkhof
      Currently Being Moderated

      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...

      • Re: How to use java classes of DC1 in DC2
        VINCENZO TURCO
        Currently Being Moderated

        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

        • Re: How to use java classes of DC1 in DC2
          Jan Penninkhof
          Currently Being Moderated

          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

           

          • Re: How to use java classes of DC1 in DC2
            VINCENZO TURCO
            Currently Being Moderated

            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

            • Re: How to use java classes of DC1 in DC2
              Jan Penninkhof
              Currently Being Moderated

              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?

  • Re: How to use java classes of DC1 in DC2
    Gopi Nidjelli
    Currently Being Moderated

    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

  • Re: How to use java classes of DC1 in DC2
    Ayyapparaj KV
    Currently Being Moderated

    Hi,

     

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

     

    Regards

    Ayyapparaj

Actions