Importing an EJB JAR file

You can import beans and other metadata from an EJB JAR file into a new or existing EJB project.

Tip: In the Project Explorer view you can also copy enterprise beans by dragging and dropping them from one EJB project to another EJB project. The import wizard will open to help you merge existing enterprise beans.
Tip:

The following paragraph applies to Windows. You can quickly drag and drop an EJB JAR file from the Windows Explorer or desktop onto the Project Explorer view. The Import wizard will open with appropriate fields already populated. If you drop on an existing EJB module, the wizard will import into that EJB module. If you drop on an enterprise application, the wizard will bind the new EJB module to this EAR.

To import an EJB JAR file into an EJB project using the Import wizard:

  1. In the J2EE perspective, click File > Import > EJB JAR file and click Next.

  2. In the EJB JAR file combination box, enter the location and name of the EJB JAR file that you want to import. You can click the Browse button to select the JAR file from the file system.

  3. In the EJB project combination box, type a new project name or select an EJB project from the drop-down list. Or, click the New button to launch the New EJB Project wizard. If a new EJB project is created, it is created with the same version as the EJB JAR being imported. If you select an EJB 2.x project and import an EJB 1.1 EJB JAR file, the version of the CMP beans is set to 1.x.

  4. If you are importing to an existing project, select Overwrite existing resources without warning.

  5. In the Target server drop-down list, select the application server that you want to target for your development. This selection affects the run time settings by modifying the class path entries for the project.

  6. Specify whether you want to add the new module to an enterprise application (EAR) project.

  7. In the EAR project combination box, type a new project name or select an existing enterprise application project from the drop-down list. Or, click the New button to launch the New Enterprise Application Project wizard.

    Note: If you type a new EAR project name, the EAR project will be created in the default location with the lowest compatible J2EE version based on the version of the project being created. If you want to specify a different version or a different location for the enterprise application, use the New Enterprise Application Project wizard.

  8. Optional: For EJB 2.x projects, you can select Add support for annotated Java classes. Select this option if you are familiar with annotations and want to use annotations to update beans rather than using the deployment descriptor.

    For more information, see Support for annotated bean classes.

  9. Click Finish to import the EJB JAR file.

Note: The .ser files in an EJB 1.0 JAR are converted into the ejb-jar.xml file for EJB 1.1 during an import.

Imported .class files

You can also import an EJB JAR file that contains binary .class files only, with no no source code. The beans can be mapped, and deployment code can be generated, or new enterprise beans that depend on the contents of the JAR can be created.

A folder called xxx.imported_classes will contain only .class files. All other files (for example, source files and .properties files) are copied to the source folder of the EJB project during import. This strategy allows the EJB tools to reflect the shape of the binary Java classes, in order to map, assemble, and deploy the imported JAR file.

On an EJB JAR export, the contents of the xxx.imported_classes folder are merged into the resulting EJB JAR. That is, the exported JAR file will be a single archive which contains the merged contents of the Java output folder of the EJB project and the xxx.imported_classes folder.

 

Related concepts

Annotation-based programming overview

 

Related tasks

Creating an EJB project
Exporting EJB projects to EJB JAR files
Importing class files to an EJB project