Skip to Content

Adding an external library facet to a J2EE Server Component Library DC

Starting with NW 7.0 SP13 the software component provided by SAP SAP_BUILDT (includes the main build plugins) is enhanced with a new Development Component with the name tc/bi/fct/extlib. This facet DC can be used to simplify DC structures a bit by allowing developers to combine the functionality of an “External Library” DC with a “J2EE Server Component Library” DC.

Use Case

You want to use some Java libraries that were produced outside of NWDI. Since you want to reuse those libraries within your application development you need to package these libaries in a component model format – a Development Component (DC).

For developments prior to NW 7.0 SP13 this meant you had to do the following:

  1. Create a new DC of type “External Library”
  2. Put the jar file(s) into the folder “library” of the “External Library” DC
  3. Create two public parts (compilation and assembly)
  4. Add the jar file(s) as entities to both public parts
  5. Build the “External Library” DC
  6. Create a second DC of type “J2EE Server Component Library”
  7. Add a build-time dependency to both public parts of the “External Library” DC
  8. Build the “J2EE Server Component Library” DC

With the new external library facet included since NW 7.0 SP13 the process is much simplier:

  1. Create a new DC of type “J2EE Server Component Library”
  2. Add a build-time dependency to the “def” public part of the new facet DC tc/bi/fct/extlib
  3. image

  4. Create a local “libs” folder below the root folder and put the jar file(s) into that folder
  5. Define that libs folder as source folder in the DC Metadata >
  6. image

    image

  7. Build the DC

 

 

While this may not look much shorter in this list here you will find that it takes much less time and keeps the DC structure much more simple. Just try it.

Verifying the result

If you kept to the explanation above you should have

  • a public part with the name deflib that contains your jar file
  • an SDA file in the gen/default/deploy folder that contains the added jar file(s)
  • a provider.xml descriptor file contained in the SDA file with appropriate entries for each jar file

Troubleshooting

Problem: The jar files of the external libraries are neither packaged into the SDA file nor copied to the public part.

Check:

The build log should contain some lines like these:
packExternalLibraries:
[pppacker] Packed 1 file or entity my-external.jar (Archive/Java Library)

Your DC MetaData should look like this. The libs folder is added as source folder in the DC metadata and a build-time dependency to tc/bi/fct/extlib exists.

image

How does it work?

The DC tc/bi/fct/extlib provides an extension to the build plugin framework that adds special handling for a “libs” source folder. Effectively this extension creates an additional Ant build file and wraps the jar files from the libs folder into a public part structure and adds that internal public part to the build. The standard build process for the J2EE Server Component Library will just see an addtional public part that is packaged like any other used public part. For the developer in the developer studio no additional public part is visible.

To report this post you need to login first.

11 Comments

You must be Logged on to comment or reply to a post.

  1. Walmir Catunda
    I tried to create the local folder (item 3) as “libraries” or “lib” and notice that it didn’t works cause “provider.xml” file generated inside the “*.sda” file didn’t have the references to “*.jar”s files. With “libs” it’s Ok.
    (0) 
  2. Anonymous
    Congratulations! Amazing approach! But as of NW7.0 SP14 was installed and I’ve created an external library in described manner and there was no public part available for another DCs. Is it normal behavior? In my case all the DCs are Local Development Components. Does tc/bi/fct/extlib component applicable for NWDI only? The metadata of external library projects is the same as you had shown in the presentation and all the needed jars was included into the deployable sda of the project but the case of usage such external library with the other DCs is not possible. The reason is that the dependency to the external library was declared but DC is unable to resolve any classes from external library neither from ‘Organize imports’ nor from manual declaration
    (0) 
    1. Karsten Geiseler
      Same problem for me with 7.00.15.
      The J2EE lib was successfully deployed, contains the jars and could be referenced, but no entities available in the deflib PP. Therefore no design time dependencies possible which makes this feature less useful 🙁
      (0) 
  3. Michael Kretz
    I tried to follow this recommendation but creation of a local ‘libs’ folder is not reflected in my NWDS. Here I still see the other folder types except for ‘libs’.
    Any suggestions?

    Thanks,
    Michael

    (0) 
  4. tulasi palnati
    Hi I followed your steps
    1.Created J2EE/Library Project
    2.I put that DC in Used DC of my WebDynpro Dc.
    3 Wrote the code but it is not recognizing my Jar file(For ex JXL.Jar workbook cannot be resolved)

    Please give me some hints

    Thanks and Regards,
    Tulasi

    (0) 
  5. Gaurang Dayal
    Hi,
    Nice blog. But even after following the steps we are still getting classpath error on building a Webdynpro DC.Incomplete classpath.
    (0) 
    1. Marc Wirth

      If you look at the build log of your WebDynpro DC the classpath of the generator should be logged. Do you see your Jar in that list?/lib/java/ folder if the build of the external library correctly put the Jar file into the public part.

      (0) 

Leave a Reply