The Java code of a building block may depend on libraries that come from Java archives. If you have a JAR file and want to use it within your building block, do the following (this process is depicted below):
- Copy the JAR file into the Eclipse project. An ideal place is a folder called “lib”, directly under the project. You may create this folder if it does not yet exist. However you decide on the location, do not copy it under the “src” folder. (One reason for not putting it under the “src” folder is that the Java build process will copy it into the binary folder, and you end up with redundant files.)
- Within the building block editor, switch to the “Overview” tab (1).
- Go to the Java section (2), and add the Jar file there (3). This entry tells the compiler that the building blocks needs this Jar file, and it will be copied into the generated project.
- To add the Jar file to the build path of your project as well, navigate to the file in the Package Explorer, and select Build Path / Add to Build Path.
- The name of the Jar file should now also appear under Referenced Libraries, and Java code within the project may refer to its contained types.
- In case your building block is part of a library and clients may need access to its contained types, you should the Eclipse project for the library export it as well. Right click on the project ion the Package Explorer and navigate to Build Path / Order and Export. Select the Jar file and check it, so it will be exported.
- If the Jar files are to be distributed under a certain license, you can also contain the license file into the project and add it to the building block, using the Required Resources (4) section in the Overview page of the editor.
- The compiler analyzes dependencies of the Java code, but does only copy Java source files that reside within projects created with the SDK. (This means, for instance, it does not follow project dependencies.) JAR-files are only copied if they are added in the way described above.
- Jar files must be added relative to the project, which is done best by right-clicking the Jar file in the Package Explorer and selecting Build Path / Add to Build Path.
If a JAR file (or any other resource) requires that it is shipped with a license file, place the license file into a folder licenses within the project of the building blocks. Refer to the licenses that are required for a building block on its overview page of the editor. These files are copied once a building block is part of an implementation.
Below are the screenshots of a building block to access Twitter. This block needs access to the two jar files dom4j.jar and jaxen.jar. These Jar files were added to the project that contains the building block, within the lib folder (1). They were also added to the class path of the project and are therefore listed under Referenced Libraries (2).
To be copied during compilation, these Jar files also have to be added to the block within the Overivew Page of the editor.