Posts in Category "Uncategorized"

How to create class/jar files for data service project without using maven

In the sample for “Create a Data Services application for the Experience Server that returns data“, it showed how to bundle your class for data service project into the template application and build/deploy the bundle using Maven. There are several ways to build the bundle without using Maven. I will add all the options here.

For our sample, the class we need to build is this:

package com.adobe.myexample;
public class EchoService {
    public String sayHello(String val){        
        return "Adobe Digital Enterprise Platform says: " +val ;
    }
}


• Using CRXDE

This is the easiest option for this task. It will compile your java class, build bundle and automatically install and start in the OSGI container. New user should use this option. For details, see “Creating a Bundle” section of the doc here. The following steps should be clear.

Note, whenever work with CRXDE Lite, you have to click on “Save ALL” at the left top after you made any change (create/modify/delete) in CRXDE, and click on refresh to make sure the change has been saved/updated.

1. Start your experience service and go to CRXDE Lite via http://localhost:4502/crxde

2. Create a project by right click on apps, select create-create project, put in the following info:
Project name: myapp
Java package: com.adobe.myexample
This will create folder /src, /install, and /components under myapp for you.

3. Create a bundle by Right click the folder apps/myapp/src, select create-create bundle , put in the following info:
Symbolic Bundle Name: com.adobe.myexample.TestEcho (this can be any name)
Bundle Name: TestEcho Bundle (this is the name will be displayed in Felix console Bundle )
Bundle Description: This is my Test Bundle
Package: com.adobe.myexample (This must be your java package name)
This will create com.adobe.myexample.TestEcho folder and com.adobe.myexample.TestEcho.bnd under it.

4. create your java code by Right click on folder /apps/myapp/src/com.adobe.myexample.TestEcho/src/main/java/com/adobe/myexample, create–>create file, enter EchoService.java as name. Make sure it is at the same folder as Activator.java. Then click on EchoService.java , and then put your java code into the right side edit area. Save it.

package com.adobe.myexample;
                   public class EchoService {
                   public String sayHello(String val){  
                       return "Adobe Digital Enterprise Platform says: " +val ;
                   }
             }

Note, If you already have your classes in a jar, then instead of creating class here, create a folder libs under /apps//src//libs/, then go to http://localhost:4502/crx and use “content loader” to import the jar into libs folder.

5. build your bundle by Right click on com.adobe.myexample.TestEcho .bnd, select Tools–>build Bundle
This will compile your java class, build bundle and automatically install and start in the OSGI container.

To verify the bundle has been install into OSGI, you can check from Felix, http://localhost:8900/system/console/bundles/
you can search by the Bundle name “ TestEcho Bundle” to find it. Click on the arrow to see the info about the Bundle. Make sure you have all the class in there and the proper packages are exported.

• Convert a jar File into an OSGi Bundle
When you have your classes in a jar, you can convert it into an OSGI Bundle, see details here

1. Creating manifest file.
This is the key to the process. In order for Bundle to be created correctly, there are several elements you need to pay attention to. You should have the following in the manifest file:
Bundle-Name: (this will be the name displayed in the Felix console Bundle tag, you can search this name to check if the bundle is installed or active.)
Bundle-Version: (should always use a higher number than the provirus version if a version has been installed, otherwise the new bundle will not be installed. But if you include SNAPSHOT like 1.0- SNAPSHOT, it will always install.
Bundle-ClassPath: .,myapp.jar (make sure you have the correct name of the jar you want to convert.)
Bundle-SymbolicName: (can be any name)
Import-Package: (if you have dependency class/jar for your class, you need to import them)
Export-Package: (this is the name of your java package name, must have this so that the class can be accessed by others)

2. Create the bundle jar (myapp-bundle.jar) by using zip or java command:
jar cvfm myapp-bundle.jar manifest.txt myapp.jar

3. Install the bundle.
Use content loader to load the jar under your app’s /install or /libs folder, like /apps/myapp/install/ and jar under /install or libs folder will be picked up.

Note, the /install or /libs should not be at more than 3 layer under apps, for example, /apps/myapp/component/bundle/install, the bundle jar will not be picked up in this case.

This can also be done by using curl command line described here.

Another option is to install OSGi bundles via CRX packages as described in this techNote.