How Do I: Create and Use a Java Control Within a Control Project?

When you are creating custom or built-in controls, you can use them locally (as part of the project from which they're being used) or package them using a control project. A control project is a special kind of project that is designed to collect related controls. The result of a control project is a JAR file that can be used within other projects.

Keep in mind that for most of the controls you create, you probably won't need a control project. The primary reason for building controls within a control project is to have the resulting JAR file for portability.

To Create a New Java Control in a Java Control Project

  1. In the Application tab, right-click the top-level folder representing your application, then click New-->Project.
  2. In the New Project dialog, in the left-hand pane, click Business Logic.
  3. In the right-hand pane, click Control Project.
  4. In the Project name box, type a name for your new control project.
  5. Click Create.

    WebLogic Workshop will create a new project folder with the name you specified. Inside the new folder will be a META-INF folder.

    It is a good idea to create separate subfolders within your project for each control to contain the control's source code. Keep in mind that a folder beneath the project's top level becomes part of the control's Java package name. With this in mind, you should create a folder structure that reflects what the various controls are designed to do. Note that you cannot create the control in the root of a project — it must be in a subfolder.

  6. To begin creating new control source files, see How Do I: Begin a New Custom Java Control? and How Do I: Start Using a Built-In Control?

    When creating new controls, you may consider setting the jc-jar group-name attribute to a name corresponding to the Java Control Project. For more information, see How Do I: Specify IDE Characteristics for a Java Control?

Before you can use the new Java control anywhere in the application, you must first build and package the control project.

To Build and Package the Control Project

WebLogic Workshop compiles the control code, packages it into a JAR file with the same name as the control project's folder, and adds the control as a library available in the application. You'll find the resulting JAR file in the Libraries folder of your application.

To Import the JAR File from Another Application

If you want to use a Java control that is in a JAR file in a different application, you will first need to add the library to your current application:
  1. Go to the Application pane, right-click the Libraries folder in the root of the application folder, and select Add Library.
  2. In the Add Library dialog, navigate to and double-click the root folder of the other application. Then double-click APP-INF-->lib, and select the JAR file. Click Open

To Use a New Java Control

  1. Open the file from which you will use the Java control.
  2. Click Add from the Data Palette view in the lower-right corner of the IDE, and select the control from the drop-down list. Alternatively, click the Insert menu, Controls, and select the control. If you set the jc-jar group-name attribute, the control will appear in a fly-out menu with the same name as the attribute.

Samples

For a control project example, see ControlProject in the SamplesApp application installed with WebLogic Workshop.

Related Topics

Getting Started with Java Controls