Tags

Feb 22, 2012

To create a JAR file in the Eclipse workbench:

1. In the Package Explorer, we can optionally pre-select one or more Java elements to export. These will be open the wizard page.

2. Either from the context menu or from the menu bar's File menu, select Export.

3. Expand the Java node in the wizard page and select JAR file. Click Next.

4. In the JAR File Specification page, select the resources that we want to export in the Select the resources to export field.

5. Select the appropriate checkbox to specify whether we want to Export generated class files and resources or Export Java source files and resources. Note: Selected resources are exported in both cases.

6. In the Select the export destination field, either type or click Browse to select a location for the JAR file.

7. Select or clear the Compress the contents of the JAR file checkbox.

8. Select or clear the Overwrite existing files without warning checkbox. If we clear this checkbox, then we will be prompted to confirm the replacement of each file that will be overwritten.

9. Note: The overwrite option is applied when writing the JAR file, the JAR description, and the manifest file.

10. Now we have two options:

11. Click Finish to create the JAR file immediately.

12. Click Next to use the JAR Packaging Options page to set advanced options, create a JAR description, or change the default manifest.

13. If we want to save the JAR file description, select the Save the description of this JAR in the workspace checkbox. A JAR file description can be used to regenerate a JAR file without using the wizard.

14. The compiler is able to generate CLASS files even when source contains errors. We have the option to exclude CLASS (but not source) files with compile errors. These files will be reported at the end, if reporting is enabled.

15. We can choose to exclude CLASS (but not source) files that have compile warnings. These files will be reported at the end.
Note: This option does not automatically exclude class files with compile errors.

16. We can choose to include the source folder path by selecting the Create source folder structure checkbox.

17. Select the Build projects if not built automatically checkbox if you want the export to perform a build before creating the JAR file.

18. Click Finish to create the JAR file immediately or Next if we want to change the default manifest.

19. If it is not already selected, click the Generate the manifest file button

20. We can now choose to save the manifest in the workbench. This will save the manifest for later use. Click Save the manifest in the workspace, then click Browse next to the Manifest file field to specify a path and file name for the manifest.

21. If we decided to save the manifest file in the previous step and you chose to save the JAR description on the previous wizard page, then you can choose to reuse it in the JAR description (by selecting the Reuse and save the manifest in the workspace checkbox). This means that the saved file will be used when the JAR file is recreated from the JAR description.This option is useful if you want to modify or replace the manifest file before recreating the JAR file from the description.

22. We can choose to seal the JAR and optionally exclude some packages from being sealed or specify a list with sealed packages. By default, nothing is sealed.

23. Click the Browse button next to the Main class field to specify the entry point for our applications.
Note: If our class is not in the list, then we forgot to select it at the beginning. Click Finish. This will create the JAR, and optionally a JAR description and a manifest file.

No comments:

Post a Comment